1) For invoice in Designesty
Controllers->designestyController.cs
CheckCouponCode method ko find karna aur jo coloured hai use change karna ya naya likhna
agar pahle se n ho to
public JsonResult CheckCouponCode(string Coupon, string ProDId)
{
if (Coupon != null && Coupon != "")
{
int Category_Id = 0;
int Sub_Category_Id = 0;
int childcategoryid = 0;
int ProductId = 0;
int productidforcoupondiscount = 0;
double Coupontotal = 0;
double FullTotal = 0;
var cart = ShoppingCart.GetCart(this.HttpContext);
var Cartdata = (from m in db.cart where m.Order_No.Equals(cart.ShoppingCartId) select m).ToList();
var CouponData= (from m in db.coupon where m.couponcode.Equals(Coupon) select m).FirstOrDefault();
if (CouponData!=null)
{
foreach (var item in Cartdata)
{
FullTotal = FullTotal + item.Total_Amount;
double Discount = 0;
double Total = 0;
var ProductData= (from m in db.product where m.Id== item.Product_Id select m).FirstOrDefault();
Category_Id = ProductData.category_id;
Sub_Category_Id = CouponData.subcategoryid;
childcategoryid = CouponData.childcategoryid;
ProductId = CouponData.productid;
var data = (from m in db.coupon
where m.couponcode.Equals(Coupon) && ((m.categoryid == Category_Id&&m.subcategoryid==0&&m.childcategoryid==0&&m.productid==0)
||(m.categoryid== Category_Id&&m.subcategoryid==Sub_Category_Id&&m.childcategoryid==0&&m.productid==0)
|| (m.categoryid == Category_Id && m.subcategoryid == Sub_Category_Id && m.childcategoryid == childcategoryid && m.productid == 0)
|| (m.categoryid==Category_Id&&m.subcategoryid==Sub_Category_Id&&m.childcategoryid==childcategoryid&&m.productid==ProductId))
&& (DateTime.Now >= m.startDate && DateTime.Now <= m.endDate)
select m).FirstOrDefault();
if (data!=null)
{
Discount = item.Total_Amount * data.percentage / 100;
Total = item.Total_Amount - Discount;
Coupontotal = Coupontotal + Discount;
productidforcoupondiscount = item.Product_Id;
}
}
if (Coupontotal > 0)
{
Session["couponam"] = Coupontotal+"-"+ productidforcoupondiscount;
return Json(new { msg = "Applied", total = FullTotal - Coupontotal, couponamount = Coupontotal });
}
else
{
return Json(new { msg = "InValid Coupon", total = "0", couponamount = "0" });
}
}
else
{
return Json(new { msg = "InValid Coupon", total = "0", couponamount = "0" });
}
}
else
{
return Json(new { msg = "InValid Coupon", total = "0", couponamount = "0" });
}
}
[HttpPost]
[ActionName("placeorder")]
public ActionResult placeorder(BillingAddress tuple)
{
try
{
string TransactionOrderId = "";
//double couponamount = 0;
// string total=Session["toatlc"]
// var orderobj = new OrderDetails();
// var amountt = Session["totalpayablecostbyuser"];
//string amount = amountt.ToString();
//string amount = "1";
//string invoiceNumber = Generatetxnid();
if (Session["UserLogin"] == null)
{
return RedirectToAction("Register", "designesty");
}
else
{
Session["forbuy"] = null;
string usid = Session["UserId"].ToString();
string UserEmail = Session["UserLogin"].ToString();
var cartId = ShoppingCart.GetCart(this.HttpContext);
int UserID = Convert.ToInt32(Session["UserId"]);
var lastorder = (from o in db.orders orderby o.Id descending select o.Id).FirstOrDefault();
string orderid = "";
if (lastorder <= 0)
{
orderid = "DNS001";
}
else
{
lastorder = lastorder + 1;
orderid = "DNS00" + lastorder;
}
TransactionOrderId = orderid;
Session["OrderId"] = orderid;
var userdata = (from u in db.register
where u.Id == UserID
select u).FirstOrDefault();
BillingAddress billadd = new BillingAddress();
billadd.Name = tuple.Name;
billadd.Mobile = tuple.Mobile;
billadd.Country = tuple.Country;
billadd.State = tuple.State;
billadd.City = tuple.City;
billadd.Pincode = tuple.Pincode;
billadd.Address = tuple.Address;
billadd.Date = DateTime.Now;
billadd.Status = true;
billadd.PlaceorderID = "";
billadd.OrderID = TransactionOrderId;
billadd.UserID = UserID;
billadd.UserEmailID = UserEmail;
db.billingaddress.Add(billadd);
db.SaveChanges();
if (cartId.ShoppingCartId != null)
{
int id = int.Parse(usid);
Session["toatlc"] = 0;
//double Coupon_Dis = Session["couponam"] == null ? 0 : double.Parse(Session["couponam"].ToString());
cartId.AddCartsummary(orderid, UserID,"Pending", Convert.ToString(Session["couponam"]));
// double TotalAmountToPay = (from c in db.cartsummary where c.User_Id == id && c.Order_No == orderid select c.Total_Price).Sum();
//string total = TotalAmountToPay.ToString();
Session["couponam"] = null;
CartEmptyCart(id);
return RedirectToAction("thanks", "designesty");
}
else
{
return RedirectToAction("Index", "designesty");
}
}
}
catch (Exception e)
{
return RedirectToAction("Index", "designesty");
}
}
Models->ShoppingCart.cs
//AddCartsummary method ko find karke pura replace kar lena
public void AddCartsummary(string OrderNo, int userId, string payment, string couponameWithID)
{
double TotalAmountWithDiscount = 0;
double TotalDiscount = 0;
double TotalAmountToPay = 0;
double couponamt = 0;
int couponAppliedID = 0;
var cartitem = (from t in storeDB.cart
where t.User_Id == userId
select t).ToList();
if(!String.IsNullOrEmpty(couponameWithID))
{
couponamt = Convert.ToDouble(couponameWithID.Split('-')[0]);
couponAppliedID= Convert.ToInt32(couponameWithID.Split('-')[1]);
}
foreach (var item in cartitem)
{
TotalAmountWithDiscount = TotalAmountWithDiscount + item.Total_Amount;
if(item.Product_Id== couponAppliedID)
{
item.Total_Amount = item.Total_Amount - couponamt;
}
string[] col = { "@Order_No", "@User_Id", "@Product_Name", "@Product_Image", "@Price", "@Discount_Price", "@Total_Price", "@Quantity", "@Order_Date" };
object[] val = { OrderNo, userId, item.Product_Name, item.Photo1, item.Price, item.Price_Discount, item.Total_Amount, item.Quantity, DateTime.Now };
retDataset("AddCartsummary", col, val);
}
TotalAmountToPay = (from c in storeDB.cartsummary where c.User_Id == userId && c.Order_No == OrderNo select c.Total_Price).Sum();
//if (couponamt > 0)
//{
// TotalAmountToPay = TotalAmountToPay - couponamt;
//}
string[] col1 = { "@Order_No", "@User_Id", "@Total_Amount_With_Discount", "@Total_Discount", "@Total_Amount_ToPay", "@Order_Date", "@Payment_Status" , "@DeliveryStatus" };
object[] val1 = { OrderNo, userId, TotalAmountWithDiscount, TotalDiscount, TotalAmountToPay, DateTime.Now, "Pending", "Pending" };
retDataset("AddOrderDetails", col1, val1);
}
CheckCouponCode method ko find karna aur jo coloured hai use change karna ya naya likhna
agar pahle se n ho to
public JsonResult CheckCouponCode(string Coupon, string ProDId)
{
if (Coupon != null && Coupon != "")
{
int Category_Id = 0;
int Sub_Category_Id = 0;
int childcategoryid = 0;
int ProductId = 0;
int productidforcoupondiscount = 0;
double Coupontotal = 0;
double FullTotal = 0;
var cart = ShoppingCart.GetCart(this.HttpContext);
var Cartdata = (from m in db.cart where m.Order_No.Equals(cart.ShoppingCartId) select m).ToList();
var CouponData= (from m in db.coupon where m.couponcode.Equals(Coupon) select m).FirstOrDefault();
if (CouponData!=null)
{
foreach (var item in Cartdata)
{
FullTotal = FullTotal + item.Total_Amount;
double Discount = 0;
double Total = 0;
var ProductData= (from m in db.product where m.Id== item.Product_Id select m).FirstOrDefault();
Category_Id = ProductData.category_id;
Sub_Category_Id = CouponData.subcategoryid;
childcategoryid = CouponData.childcategoryid;
ProductId = CouponData.productid;
var data = (from m in db.coupon
where m.couponcode.Equals(Coupon) && ((m.categoryid == Category_Id&&m.subcategoryid==0&&m.childcategoryid==0&&m.productid==0)
||(m.categoryid== Category_Id&&m.subcategoryid==Sub_Category_Id&&m.childcategoryid==0&&m.productid==0)
|| (m.categoryid == Category_Id && m.subcategoryid == Sub_Category_Id && m.childcategoryid == childcategoryid && m.productid == 0)
|| (m.categoryid==Category_Id&&m.subcategoryid==Sub_Category_Id&&m.childcategoryid==childcategoryid&&m.productid==ProductId))
&& (DateTime.Now >= m.startDate && DateTime.Now <= m.endDate)
select m).FirstOrDefault();
if (data!=null)
{
Discount = item.Total_Amount * data.percentage / 100;
Total = item.Total_Amount - Discount;
Coupontotal = Coupontotal + Discount;
productidforcoupondiscount = item.Product_Id;
}
}
if (Coupontotal > 0)
{
Session["couponam"] = Coupontotal+"-"+ productidforcoupondiscount;
return Json(new { msg = "Applied", total = FullTotal - Coupontotal, couponamount = Coupontotal });
}
else
{
return Json(new { msg = "InValid Coupon", total = "0", couponamount = "0" });
}
}
else
{
return Json(new { msg = "InValid Coupon", total = "0", couponamount = "0" });
}
}
else
{
return Json(new { msg = "InValid Coupon", total = "0", couponamount = "0" });
}
}
[HttpPost]
[ActionName("placeorder")]
public ActionResult placeorder(BillingAddress tuple)
{
try
{
string TransactionOrderId = "";
//double couponamount = 0;
// string total=Session["toatlc"]
// var orderobj = new OrderDetails();
// var amountt = Session["totalpayablecostbyuser"];
//string amount = amountt.ToString();
//string amount = "1";
//string invoiceNumber = Generatetxnid();
if (Session["UserLogin"] == null)
{
return RedirectToAction("Register", "designesty");
}
else
{
Session["forbuy"] = null;
string usid = Session["UserId"].ToString();
string UserEmail = Session["UserLogin"].ToString();
var cartId = ShoppingCart.GetCart(this.HttpContext);
int UserID = Convert.ToInt32(Session["UserId"]);
var lastorder = (from o in db.orders orderby o.Id descending select o.Id).FirstOrDefault();
string orderid = "";
if (lastorder <= 0)
{
orderid = "DNS001";
}
else
{
lastorder = lastorder + 1;
orderid = "DNS00" + lastorder;
}
TransactionOrderId = orderid;
Session["OrderId"] = orderid;
var userdata = (from u in db.register
where u.Id == UserID
select u).FirstOrDefault();
BillingAddress billadd = new BillingAddress();
billadd.Name = tuple.Name;
billadd.Mobile = tuple.Mobile;
billadd.Country = tuple.Country;
billadd.State = tuple.State;
billadd.City = tuple.City;
billadd.Pincode = tuple.Pincode;
billadd.Address = tuple.Address;
billadd.Date = DateTime.Now;
billadd.Status = true;
billadd.PlaceorderID = "";
billadd.OrderID = TransactionOrderId;
billadd.UserID = UserID;
billadd.UserEmailID = UserEmail;
db.billingaddress.Add(billadd);
db.SaveChanges();
if (cartId.ShoppingCartId != null)
{
int id = int.Parse(usid);
Session["toatlc"] = 0;
//double Coupon_Dis = Session["couponam"] == null ? 0 : double.Parse(Session["couponam"].ToString());
cartId.AddCartsummary(orderid, UserID,"Pending", Convert.ToString(Session["couponam"]));
// double TotalAmountToPay = (from c in db.cartsummary where c.User_Id == id && c.Order_No == orderid select c.Total_Price).Sum();
//string total = TotalAmountToPay.ToString();
Session["couponam"] = null;
CartEmptyCart(id);
return RedirectToAction("thanks", "designesty");
}
else
{
return RedirectToAction("Index", "designesty");
}
}
}
catch (Exception e)
{
return RedirectToAction("Index", "designesty");
}
}
Models->ShoppingCart.cs
//AddCartsummary method ko find karke pura replace kar lena
public void AddCartsummary(string OrderNo, int userId, string payment, string couponameWithID)
{
double TotalAmountWithDiscount = 0;
double TotalDiscount = 0;
double TotalAmountToPay = 0;
double couponamt = 0;
int couponAppliedID = 0;
var cartitem = (from t in storeDB.cart
where t.User_Id == userId
select t).ToList();
if(!String.IsNullOrEmpty(couponameWithID))
{
couponamt = Convert.ToDouble(couponameWithID.Split('-')[0]);
couponAppliedID= Convert.ToInt32(couponameWithID.Split('-')[1]);
}
foreach (var item in cartitem)
{
TotalAmountWithDiscount = TotalAmountWithDiscount + item.Total_Amount;
if(item.Product_Id== couponAppliedID)
{
item.Total_Amount = item.Total_Amount - couponamt;
}
string[] col = { "@Order_No", "@User_Id", "@Product_Name", "@Product_Image", "@Price", "@Discount_Price", "@Total_Price", "@Quantity", "@Order_Date" };
object[] val = { OrderNo, userId, item.Product_Name, item.Photo1, item.Price, item.Price_Discount, item.Total_Amount, item.Quantity, DateTime.Now };
retDataset("AddCartsummary", col, val);
}
TotalAmountToPay = (from c in storeDB.cartsummary where c.User_Id == userId && c.Order_No == OrderNo select c.Total_Price).Sum();
//if (couponamt > 0)
//{
// TotalAmountToPay = TotalAmountToPay - couponamt;
//}
string[] col1 = { "@Order_No", "@User_Id", "@Total_Amount_With_Discount", "@Total_Discount", "@Total_Amount_ToPay", "@Order_Date", "@Payment_Status" , "@DeliveryStatus" };
object[] val1 = { OrderNo, userId, TotalAmountWithDiscount, TotalDiscount, TotalAmountToPay, DateTime.Now, "Pending", "Pending" };
retDataset("AddOrderDetails", col1, val1);
}
Comments
Post a Comment