public ActionResult Create(AllModel model) { try { if (model.tblVocabularyArray != null) { foreach (var item in model.tblVocabularyArray) { var check = db.vocabularies.FirstOrDefault(x => x.code == item.code); if (check == null) { db.vocabularies.Add(item); } } } db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(RedirectToAction("Index")); }
public ActionResult Create(country country, HttpPostedFileBase[] files) { if (ModelState.IsValid) { if (files != null) { for (int i = 0; i < files.Length; i++) { if (files[i] != null) { string path = ""; path = Path.Combine(Server.MapPath("/Content/ProductImage"), Path.GetFileName(files[i].FileName)); var picId = db.artlinks.OrderByDescending(x => x.LINENO).FirstOrDefault(); files[i].SaveAs(path); country.urlimage = "/Content/ProductImage/" + files[i].FileName; } } } db.countries.Add(country); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(country)); }
public ActionResult Create(menu menu) { if (ModelState.IsValid) { db.menus.Add(menu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(menu)); }
public ActionResult Create(warehouse warehouse) { if (ModelState.IsValid) { db.warehouses.Add(warehouse); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(warehouse)); }
public ActionResult Create(catalogue catalogue) { if (ModelState.IsValid) { db.catalogues.Add(catalogue); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(catalogue)); }
public ActionResult Create(city city) { if (ModelState.IsValid) { db.cities.Add(city); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(city)); }
public ActionResult Create([Bind(Include = "Id,Name,Images,Code,Status")] slider slider) { if (ModelState.IsValid) { db.sliders.Add(slider); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(slider)); }
public ActionResult Create(shippingfee shippingfee) { if (ModelState.IsValid) { db.shippingfees.Add(shippingfee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shippingfee)); }
public ActionResult Create(category category) { if (ModelState.IsValid) { category.CREATED = DateTime.Now; category.LASTCHANGE = DateTime.Now; db.categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create(AllModel model, HttpPostedFileBase[] inputfile) { if (model.tblStockCodArray != null) { var stoclF = new stockcod { CodeLanguage = model.tblStockCodArray[0].CodeLanguage.ToLower(), STOCKNAME = model.tblStockCodArray[0].STOCKNAME, STOCKCODE = model.tblStockCodArray[0].STOCKCODE, CREATED = DateTime.Now, LASTCHANGE = DateTime.Now }; db.stockcods.Add(stoclF); db.SaveChanges(); var updateItem = db.stockcods.Find(stoclF.STOCKNO); updateItem.IdCurrentItem = stoclF.STOCKNO; db.Entry(updateItem).State = EntityState.Modified; db.SaveChanges(); foreach (var item in model.tblStockCodArray.Skip(1).ToList()) { var tblStore = new stockcod { CodeLanguage = item.CodeLanguage.ToLower(), IdCurrentItem = stoclF.IdCurrentItem, STOCKNAME = item.STOCKNAME, STOCKCODE = item.STOCKCODE, CREATED = stoclF.CREATED, LASTCHANGE = stoclF.LASTCHANGE }; db.stockcods.Add(tblStore); } db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(AllModel model, HttpPostedFileBase[] files) { if (ModelState.IsValid) { var checkStock = db.stocks.FirstOrDefault(x => x.STOCKNO == model.tblStock.STOCKNO && x.ARTNO == model.tblStock.ARTNO); if (checkStock != null) { var tblStock = db.stocks.Find(checkStock.LINENO); tblStock.VOLUME = checkStock.VOLUME + model.tblStock.VOLUME; tblStock.SIZENO = model.tblStock.SIZENO; db.Entry(tblStock).State = EntityState.Modified; } else { db.stocks.Add(model.tblStock); db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(model.tblStock)); }
public ActionResult GoogleTag(seo model) { if (model.id != 0) { var se = db.seos.Find(model.id); se.googleanalys = model.googleanalys; se.description = model.description; se.metatag = model.metatag; se.type = model.type; se.page = model.page; se.link = model.link; se.keyword = model.keyword; se.title = model.title; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } else { db.seos.Add(model); db.SaveChanges(); } return(View(model)); }
public ActionResult Create(AllModel model, HttpPostedFileBase[] inputfile) { if (model.tblStoreArray != null) { var storeF = new store { CodeLanguage = model.tblStoreArray[0].CodeLanguage.ToLower(), Name = model.tblStoreArray[0].Name, Location = model.tblStoreArray[0].Location, Description = model.tblStoreArray[0].Description }; db.stores.Add(storeF); db.SaveChanges(); var updateItem = db.stores.Find(storeF.Id); updateItem.IdCurrentItem = storeF.Id; db.Entry(updateItem).State = EntityState.Modified; db.SaveChanges(); foreach (var item in model.tblStoreArray.Skip(1).ToList()) { var tblStore = new store { CodeLanguage = item.CodeLanguage.ToLower(), IdCurrentItem = storeF.IdCurrentItem, Name = item.Name, Location = item.Location, Description = item.Description, }; db.stores.Add(tblStore); } if (inputfile != null) { for (int i = 0; i < inputfile.Length; i++) { if (inputfile[i] != null) { string path = ""; path = Path.Combine(Server.MapPath("/Content/ProductImage"), Path.GetFileName(inputfile[i].FileName)); inputfile[i].SaveAs(path); updateItem.UrlImage = "/Content/ProductImage/" + inputfile[i].FileName; } } } db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(promotion promotion, HttpPostedFileBase[] files, String[] usertypes, string value) { ViewBag.Error = ""; try { if (ModelState.IsValid) { if (files != null) { for (int i = 0; i < files.Length; i++) { if (files[i] != null) { string path = ""; path = Path.Combine(Server.MapPath("/Content/ProductImage"), Path.GetFileName(files[i].FileName)); var picId = db.artlinks.OrderByDescending(x => x.LINENO).FirstOrDefault(); files[i].SaveAs(path); } } } //var proId = db.promotions.OrderByDescending(x => x.PROMOTIONNO).FirstOrDefault(); //if (proId != null) //{ // promotion.PROMOTIONNO = proId.PROMOTIONNO + 1; //} //else //{ // promotion.PROMOTIONNO = 1; //} promotion.TYPEUSERS = String.Join(",", usertypes); promotion.CREATED = DateTime.Now; promotion.LASTCHANGE = DateTime.Now; db.promotions.Add(promotion); db.SaveChanges(); if (promotion.QUANTITY != 0) { for (int i = 0; i < promotion.QUANTITY; i++) { var tblPro = new promotionrule { PROMOTIONCODE = "KM" + Guid.NewGuid().ToString().Substring(0, 6).ToUpper(), PROMOTIONNO = promotion.PROMOTIONNO, ELIGIBILITYNO = 1, TYPENO = promotion.TYPENO, ADJUSTMENTVALUE = decimal.Parse(promotion.VALUEPROMOTION), ADJUSTMENTTYPENO = 1, CREATED = DateTime.Now, LASTCHANGE = DateTime.Now, PRICEGROUPNO = 1 }; db.promotionrules.Add(tblPro); } db.SaveChanges(); } else { /* var tblPro = new promotionrule * { * PROMOTIONCODE = promotion.PROMOTIONCODE.ToUpper(), * PROMOTIONNO = promotion.PROMOTIONNO, * ELIGIBILITYNO = 1, * TYPENO = promotion.TYPENO, * ADJUSTMENTVALUE = decimal.Parse(promotion.VALUEPROMOTION), * ADJUSTMENTTYPENO = 1, * CREATED = DateTime.Now, * LASTCHANGE = DateTime.Now, * PRICEGROUPNO = 1 * }; * db.promotionrules.Add(tblPro); * * db.SaveChanges();*/ } return(RedirectToAction("Index")); } } catch (Exception ex) { throw ex; } return(View(promotion)); }
public ActionResult Create(AllModel model, HttpPostedFileBase inputfile) { // if (ModelState.IsValid) // { try { //save file if (model.tblFileArray != null && inputfile.ContentLength > 0) { string path = ""; try { path = Path.Combine(Server.MapPath("/UploadFile"), Path.GetFileName(inputfile.FileName)); inputfile.SaveAs(path); //save other infomation var matagroup = new file(); matagroup.FileName = inputfile.FileName; matagroup.Status = "Active"; matagroup.FileAddress = path; matagroup.Title = model.tblFileArray[0].Title; matagroup.Description = model.tblFileArray[0].Description; matagroup.CodeLanguage = model.tblFileArray[0].CodeLanguage; matagroup.UploadDate = DateTime.Now; matagroup.UploadBy = User.Identity.Name; matagroup.Kind = inputfile.ContentType; db.files.Add(matagroup); db.SaveChanges(); var updatematagroup = db.files.Find(matagroup.Id); updatematagroup.IdCurrentItem = matagroup.Id; db.Entry(updatematagroup).State = EntityState.Modified; db.SaveChanges(); foreach (var item in model.tblFileArray.Skip(1).ToList()) { var matagroupL = new file(); matagroupL.FileName = item.FileName; matagroupL.Status = "Active"; matagroupL.FileAddress = path; matagroupL.Title = item.Title; matagroupL.Description = item.Description; matagroupL.CodeLanguage = item.CodeLanguage; matagroupL.UploadDate = DateTime.Now; matagroupL.UploadBy = User.Identity.Name; matagroupL.Kind = inputfile.ContentType; db.files.Add(matagroupL); } db.SaveChanges(); ViewBag.Message = "File uploaded successfully"; //save other infomation } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } } else { ViewBag.Message = "You have not specified a file."; } } catch (Exception ex) { } return(RedirectToAction("Index")); }
public ActionResult Create(AllModel model, HttpPostedFileBase[] inputfile) { try { if (model.tblProductArray != null) { var artCode = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(); var itemF = new item(); itemF.ARTTYPE = 1; itemF.CREATED = DateTime.Now; itemF.LASTCHANGE = DateTime.Now; itemF.ARTCODE = artCode; itemF.ARTNAME = model.tblProductArray[0].ARTNAME; itemF.INFO = model.tblProductArray[0].INFO; itemF.CodeLanguage = model.tblProductArray[0].CodeLanguage.ToLower(); itemF.GROUPNO = model.tblitem.GROUPNO; itemF.IsBestSeller = model.tblitem.IsBestSeller; itemF.EXPORTABLE = model.tblitem.EXPORTABLE; itemF.SPECIALOFFER = model.tblitem.SPECIALOFFER; itemF.STOCKITEM = model.tblitem.STOCKITEM; itemF.AUTHORIZABLE = model.tblitem.AUTHORIZABLE; itemF.RESTRICTED = model.tblitem.RESTRICTED; itemF.NOTPOST = model.tblitem.NOTPOST; itemF.NOTADDPOSTAGEFEE = model.tblitem.NOTADDPOSTAGEFEE; itemF.WIDTH = model.tblitem.WIDTH; itemF.WEIGHT = model.tblitem.WEIGHT; itemF.LEN = model.tblitem.LEN; itemF.HEIGHT = model.tblitem.HEIGHT; itemF.WEBPRICE = model.tblitem.WEBPRICE; db.items.Add(itemF); db.SaveChanges(); var updateItem = db.items.Find(itemF.ARTNO); updateItem.IdCurrentItem = itemF.ARTNO; db.Entry(updateItem).State = EntityState.Modified; db.SaveChanges(); foreach (var item in model.tblProductArray.Skip(1).ToList()) { var tblItem = new item(); tblItem.ARTTYPE = 1; tblItem.CREATED = DateTime.Now; tblItem.LASTCHANGE = DateTime.Now; tblItem.ARTCODE = itemF.ARTCODE; tblItem.ARTNAME = item.ARTNAME; tblItem.INFO = item.INFO; tblItem.CodeLanguage = item.CodeLanguage.ToLower(); tblItem.GROUPNO = model.tblitem.GROUPNO; tblItem.IsBestSeller = model.tblitem.IsBestSeller; tblItem.EXPORTABLE = model.tblitem.EXPORTABLE; tblItem.SPECIALOFFER = model.tblitem.SPECIALOFFER; tblItem.STOCKITEM = model.tblitem.STOCKITEM; tblItem.AUTHORIZABLE = model.tblitem.AUTHORIZABLE; tblItem.RESTRICTED = model.tblitem.RESTRICTED; tblItem.NOTPOST = model.tblitem.NOTPOST; tblItem.NOTADDPOSTAGEFEE = model.tblitem.NOTADDPOSTAGEFEE; tblItem.WIDTH = model.tblitem.WIDTH; tblItem.WEIGHT = model.tblitem.WEIGHT; tblItem.LEN = model.tblitem.LEN; tblItem.HEIGHT = model.tblitem.HEIGHT; tblItem.IdCurrentItem = itemF.IdCurrentItem; tblItem.WEBPRICE = model.tblitem.WEBPRICE; db.items.Add(tblItem); } db.SaveChanges(); if (inputfile != null) { for (int i = 0; i < inputfile.Length; i++) { if (inputfile[i] != null) { string path = ""; path = Path.Combine(Server.MapPath("/Content/ProductImage"), Path.GetFileName(inputfile[i].FileName)); inputfile[i].SaveAs(path); var i1 = itemF.IdCurrentItem > 0 ? itemF.IdCurrentItem:0; if (i1 != null) { var tblPic = new artlink { ARTNO = (int)i1, LASTCHANGE = DateTime.Now, CREATED = DateTime.Now, LINK = inputfile[i].FileName }; db.artlinks.Add(tblPic); } db.SaveChanges(); } } } } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(RedirectToAction("Index")); }
public ActionResult Create(AllModel model, HttpPostedFileBase[] inputfile) { if (model.tblMasterMetaGroupArray != null) { var matagroup = new metagrup(); matagroup.PARENTNO = 0; matagroup.IsActive = model.tblMasterMetaGroup.IsActive; matagroup.CREATED = DateTime.Now; matagroup.METAGROUPNAME = model.tblMasterMetaGroupArray[0].METAGROUPNAME; matagroup.METAGROUPCODE = model.tblMasterMetaGroupArray[0].METAGROUPCODE; matagroup.CodeLanguage = model.tblMasterMetaGroupArray[0].CodeLanguage; db.metagrups.Add(matagroup); db.SaveChanges(); var updatematagroup = db.metagrups.Find(matagroup.METAGROUPNO); updatematagroup.IdCurrentItem = matagroup.METAGROUPNO; db.Entry(updatematagroup).State = EntityState.Modified; db.SaveChanges(); foreach (var item in model.tblMasterMetaGroupArray.Skip(1).ToList()) { item.PARENTNO = 0; item.IsActive = model.tblMasterMetaGroup.IsActive; item.CREATED = DateTime.Now; item.IdCurrentItem = updatematagroup.IdCurrentItem; db.metagrups.Add(item); } db.SaveChanges(); if (inputfile != null) { for (int i = 0; i < inputfile.Length; i++) { if (inputfile[i] != null) { var fname = matagroup.IdCurrentItem + "." + inputfile[i].FileName.Split('.').Last(); string path = Server.MapPath("~/Content/MetagroupImage"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path + "/", fname); inputfile[i].SaveAs(path); } } } } return(RedirectToAction("Index")); }
public ActionResult Create(order order, int?checkBilldingShipping) { if (ModelState.IsValid) { if (Session["ShoppingCart"] == null) { return(RedirectToAction("UpdateCart", "Home")); } else { try { var oldPriceOrder = 0.0; if (order.ocid > 0) { var _order = db.orders.Where(t => t.ocid == order.ocid).FirstOrDefault(); oldPriceOrder = _order.paid_amount.HasValue ? _order.paid_amount.Value : 0; db.Entry(_order).State = EntityState.Detached; db.SaveChanges(); } order.d_companyname = string.IsNullOrEmpty(order.d_companyname) ? order.companyname : order.d_companyname; order.d_fname = string.IsNullOrEmpty(order.d_fname) ? order.fname : order.d_fname; order.d_lname = string.IsNullOrEmpty(order.d_lname) ? order.lname : order.d_lname; order.d_email = string.IsNullOrEmpty(order.d_email) ? order.email : order.d_email; order.d_phone = string.IsNullOrEmpty(order.d_phone) ? order.phone : order.d_phone; order.d_addr1 = string.IsNullOrEmpty(order.d_addr1) ? order.addr1 : order.d_addr1; if (checkBilldingShipping.HasValue && checkBilldingShipping.Value == 1) { order.b_companyname = string.IsNullOrEmpty(order.d_companyname) ? order.companyname : order.d_companyname; order.b_fname = string.IsNullOrEmpty(order.d_fname) ? order.fname : order.d_fname; order.b_lname = string.IsNullOrEmpty(order.d_lname) ? order.lname : order.d_lname; order.b_email = string.IsNullOrEmpty(order.d_email) ? order.email : order.d_email; order.b_phone = string.IsNullOrEmpty(order.d_phone) ? order.phone : order.d_phone; order.b_addr1 = string.IsNullOrEmpty(order.d_addr1) ? order.addr1 : order.d_addr1; } order.status = "2"; if (order.payoption == "PayPal") { order.paid_status = 2; } if (order.payoption == "COD") { order.paid_status = 1; } ShoppingCart Cart = new ShoppingCart(); Cart = (ShoppingCart)Session["ShoppingCart"]; order.paid_amount = Cart.CartTotal + Cart.taxTotal; String randomKey = Guid.NewGuid().ToString(); if (order.ocid == 0) { order.paid_key = randomKey; db.orders.Add(order); db.SaveChanges(); } else { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } Cart.paid_key = order.paid_key; WebApplication1.Models.AllLoggedUserInfo userFullInfo = (WebApplication1.Models.AllLoggedUserInfo)Session["LoggedAccount"]; if (userFullInfo != null) { var user = db.users.Find(userFullInfo.user.Id); user.paidorder = (user.paidorder ?? 0) + (decimal)Cart.CartTotal + (decimal)(order.feeshipping ?? 0) - (decimal)oldPriceOrder; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } double cartAmount = 0; string currencyName = "USD"; ordersetting ordersetting = db.ordersettings.Where(t => t.status == 1).FirstOrDefault(); if (ordersetting != null) { currencyName = ordersetting.name; } var itemList = new ItemList(); var items = new List <Item>(); String paypalURL = ""; var paypayconfig = new PayPalConfiguration(); var apiContext = paypayconfig.GetAPIContext(); var _orderdetails = db.orderdetails.Where(t => t.ocid == order.ocid).ToList(); var listItems = _orderdetails.Select(t => t.ocdetailcode); var _items = db.items.Where(t => listItems.Contains(t.ARTCODE)).ToList(); foreach (var item in _orderdetails) { if (item.stockId.HasValue && item.stockId.Value > 0) { var _item = _items.FirstOrDefault(t => t.ARTCODE == item.ocdetailcode); if (_item != null) { var _stock = db.stocks.Where(t => t.ARTNO == item.itemId && t.STOCKNO == item.stockId).FirstOrDefault(); _stock.VOLUME += item.ocdetailqty.Value; db.Entry(_stock).State = EntityState.Modified; } } } db.orderdetails.RemoveRange(_orderdetails); var _listItems = Cart.cartItem.Select(t => t.Code); var __items = db.items.Where(t => _listItems.Contains(t.ARTCODE)).ToList(); foreach (var item in Cart.cartItem) { orderdetail od = new orderdetail(); od.ocid = order.ocid; od.ocdetailcode = item.Code; od.ocdetailname = item.Name; od.ocdetailprice = item.Price; od.ocdetailqty = item.Qty; od.ocdetailgst = item.Tax / item.Qty; od.stockId = item.StockId; if (item.StockId > 0) { var _item = __items.FirstOrDefault(t => t.ARTCODE == od.ocdetailcode); if (_item != null) { var _stock = db.stocks.Where(t => t.ARTNO == _item.ARTNO && t.STOCKNO == item.StockId).FirstOrDefault(); _stock.VOLUME -= item.Qty; db.Entry(_stock).State = EntityState.Modified; od.itemId = _item.ARTNO; } } db.orderdetails.Add(od); var Item = new Item(); Item.name = item.Code + " - " + item.Name; Item.currency = currencyName; Item.price = (item.Price + (item.Tax / item.Qty)) + ""; Item.quantity = item.Qty + ""; items.Add(Item); } if (order.feeshipping.HasValue && order.feeshipping.Value > 0) { var Item = new Item(); Item.name = "Fee Shipping"; Item.currency = currencyName; Item.price = order.feeshipping + ""; Item.quantity = "1"; items.Add(Item); } if (Cart.promotion != null) { if (Cart.promotion.TYPENO == 0) { var Item = new Item(); Item.name = "Discount Promotion"; Item.currency = currencyName; Item.price = "-" + Cart.PromotionTotal + ""; Item.quantity = "1"; items.Add(Item); } } cartAmount = Cart.CartTotal + Cart.taxTotal + order.feeshipping ?? 0; cartAmount = Math.Round(cartAmount, 2); itemList.items = items; db.SaveChanges(); if (order.payoption == "PayPal") { var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = UrlHelper.Root + "Checkout/PayPalCancel?" + UrlHelper.ToQueryString(new { paid_key = order.paid_key }), return_url = UrlHelper.Root + "Checkout/PayPalSuccess?" + UrlHelper.ToQueryString(new { paid_key = order.paid_key }) }; var paypalAmount = new Amount() { currency = currencyName, total = cartAmount.ToString() }; var transactionList = new List <PayPal.Api.Transaction>(); PayPal.Api.Transaction transaction = new PayPal.Api.Transaction(); transaction.amount = paypalAmount; transaction.item_list = itemList; transactionList.Add(transaction); var payment = new Payment() { intent = "Sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; try { var createdPayment = payment.Create(apiContext); var links = createdPayment.links.GetEnumerator(); while (links.MoveNext()) { var link = links.Current; if (link.rel.ToLower().Trim().Equals("approval_url")) { paypalURL = link.href; } } return(Redirect(paypalURL)); } catch (PaymentsException ex) { paypalURL = "ERROR: " + ex.Response; } } else { SendTemplateEmail(order.d_email, order.d_email, "", "Order Success #" + order.ocid + "" + DateTime.Now.Day, 1, Cart, order); SendTemplateEmail(order.d_email, order.d_email, "", "Order Success #" + order.ocid + "" + DateTime.Now.Day, 3, Cart, order); return(RedirectToAction("Thankyou")); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } } } return(RedirectToAction("Create")); }
public ActionResult Create(order order, string[] totalProduct) { try { order.submitDate = DateTime.Now; db.orders.Add(order); db.SaveChanges(); if (totalProduct != null) { var listItem = totalProduct.ToList().Distinct().ToList(); foreach (var item in listItem) { var itemId = int.Parse(item.Split('_')[0]); var tblItem = db.items.FirstOrDefault(x => x.ARTNO == itemId); var tblOrderDetail = db.orderdetails.FirstOrDefault(x => x.itemId == itemId && x.ocid == order.ocid); if (tblOrderDetail == null) { var tblOrder = new orderdetail { ocid = order.ocid, itemId = itemId, ocdetailqty = int.Parse(item.Split('_')[1]), ocdetailname = tblItem != null ? tblItem.ARTNAME : "" }; db.orderdetails.Add(tblOrder); } else { tblOrderDetail.ocdetailqty = int.Parse(item.Split('_')[1]); db.Entry(tblOrderDetail).State = EntityState.Modified; } } db.SaveChanges(); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(RedirectToAction("Index")); }
public ActionResult CreateUser(user user) { if (ModelState.IsValid) { user.status = "active"; user.createdate = DateTime.Now; user.updatedate = DateTime.Now; db.users.Add(user); db.SaveChanges(); user_role ur = new user_role(); ur.userid = user.Id; ur.roleid = 7; ur.status = "active"; db.user_role.Add(ur); userdata ud = new userdata(); ud.userid = user.Id; db.userdatas.Add(ud); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult SaveSignup(user user) { user.status = "active"; user.createdate = DateTime.Now; user.updatedate = DateTime.Now; user.type = 1; user.discount = 0; db.users.Add(user); db.SaveChanges(); user_role ur = new user_role(); ur.userid = user.Id; ur.roleid = 6; ur.status = "active"; db.user_role.Add(ur); userdata ud = new userdata(); ud.userid = user.Id; db.userdatas.Add(ud); db.SaveChanges(); var t = SendTemplateEmail(user.email, user.email, "", "Email register success", 1); var tem = db.users.FirstOrDefault(m => m.username == user.username && m.password == user.password); if (tem != null) { Session["LoggedAccount"] = null; AllLoggedUserInfo userFullInfo = new AllLoggedUserInfo(tem); Session["LoggedAccount"] = userFullInfo; string decodedUrl = ""; if (!string.IsNullOrEmpty(Url.Action("AccountInfo", "Account", new { id = user.Id }))) { decodedUrl = Server.UrlDecode(Url.Action("AccountInfo", "Account", new { id = user.Id })); } if (decodedUrl != "" && !decodedUrl.Contains("Login")) { return(Redirect(decodedUrl)); } if (userFullInfo.role.RoleName == "super_admin") { return(RedirectToAction("Index", "Admin")); } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Login", "Home", new { message = "Acount do not exist." })); } }
public ActionResult Create(item item, HttpPostedFileBase[] inputfile) { var category = db.categories.ToList(); category.Insert(0, new category { CATEGORYNO = 0, CATEGORYNAME = "Select Category" }); ViewBag.CategoryList = category; ViewBag.WarhouseList = db.warehouses.ToList(); ViewBag.stockList = db.stockcods.ToList(); ViewBag.StoreList = db.stores.ToList(); var metagroup = db.metagrups.ToList(); metagroup.Insert(0, new metagrup { METAGROUPNO = 0, METAGROUPNAME = "Select Meta Group" }); ViewBag.MetaGroupList = metagroup; try { item.ARTTYPE = 1; item.EXPORTABLE = ""; item.ARTCODE = string.IsNullOrEmpty(item.ARTCODE)? Guid.NewGuid().ToString().Substring(0, 6).ToUpper(): item.ARTCODE; item.CREATED = DateTime.Now; item.LASTCHANGE = DateTime.Now; db.items.Add(item); db.SaveChanges(); for (int i = 0; i < inputfile.Length; i++) { if (inputfile[i] != null) { string path = ""; path = Path.Combine(Server.MapPath("/Content/ProductImage"), Path.GetFileName(inputfile[i].FileName)); var picId = db.artlinks.OrderByDescending(x => x.LINENO).FirstOrDefault(); inputfile[i].SaveAs(path); var tblPic = new artlink { LINENO = picId.LINENO + 1, ARTNO = item.ARTNO, LASTCHANGE = DateTime.Now, CREATED = DateTime.Now, LINK = path }; db.artlinks.Add(tblPic); db.SaveChanges(); } } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(RedirectToAction("Index")); }