public ActionResult Add(ProductViewModel productViewModel) { try { var vendor = (OctopusCodesMultiVendor.Models.Vendor)SessionPersister.account; if (ModelState.IsValid) { productViewModel.product.VendorId = vendor.Id; productViewModel.product.Views = 0; ocmde.Products.Add(productViewModel.product); ocmde.SaveChanges(); return(RedirectToAction("Index")); } var categories = ocmde.Categories.Where(c => c.VendorId == vendor.Id).Select(c => new { Id = c.Id, Name = c.Name, Group = c.Category2.Name }).ToList(); productViewModel.CategoriesMultiLevel = new SelectList(categories, "Id", "Name", "Group", 1); return(View("Add", productViewModel)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Product", "Add"))); } }
public IActionResult SendMessage(int id, Message message) { try { var customer = ocmde.AccountCustomer.SingleOrDefault(a => a.Email.Equals(HttpContext.Session.GetString("email_customer"))); var newMessage = new Message() { DateCreation = DateTime.Now, Status = false, CustomerId = customer.Id, Title = message.Title, Body = message.Body, VendorId = id }; ocmde.Messages.Add(newMessage); ocmde.SaveChanges(); ViewBag.vendor = ocmde.Vendors.Find(id); ViewBag.Result = sharedLocalizer["messages_sent_success"]; return(View("SendMessage", new Message() { VendorId = id })); } catch (Exception e) { throw; } }
public IActionResult Save() { try { if (HttpContext.Session.GetString("username_customer") == null) { return(RedirectToAction("Index", "Login", new { Area = "CustomerPanel" })); } else { var customer = ocmde.AccountCustomer.SingleOrDefault(a => a.Email.Equals(HttpContext.Session.GetString("email_customer"))); var cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); var vendorIds = cart.Select(i => i.VendorId).Distinct().ToList(); vendorIds.ForEach(id => { var currentVendor = ocmde.Vendors.Find(id); // Create new order Orders order = new Orders() { CustomerId = customer.Id, DateCreation = DateTime.Now, Name = sharedLocalizer["New_Order_for_Vendor"] + " " + currentVendor.Name, OrderStatusId = 1, VendorId = id }; ocmde.Orderss.Add(order); ocmde.SaveChanges(); // Create order details cart.Where(i => i.VendorId == id).ToList().ForEach(i => { OrdersDetail ordersDetail = new OrdersDetail() { OrderId = order.Id, Price = i.Price, Quantity = i.Quantity, ProductId = i.Id }; ocmde.OrdersDetails.Add(ordersDetail); ocmde.SaveChanges(); }); }); // Remove Cart HttpContext.Session.Remove("Cart"); return(RedirectToAction("Index", "Orders", new { Area = "CustomerPanel" })); } } catch (Exception e) { throw; } }
public IActionResult Status(int id) { try { var customer = ocmde.AccountCustomer.SingleOrDefault(a => a.Id == id); customer.Status = !customer.Status; ocmde.SaveChanges(); return(RedirectToAction("Customer", "Account")); } catch (Exception e) { throw; } }
public ActionResult Edit(Setting setting, HttpPostedFileBase logo) { try { if (logo != null && logo.ContentLength > 0 && !logo.ContentType.Contains("image")) { ViewBag.errorPhoto = Resources.Vendor.Photo_Invalid; return(View("Edit", ocmde.Settings.Find(setting.Id))); } if (ModelState.IsValid) { var currentSetting = ocmde.Settings.Find(setting.Id); if (logo != null && logo.FileName.Length != 0) { var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetFileName(logo.FileName); logo.SaveAs(Path.Combine(Server.MapPath("~/Content/User/Images"), fileName)); currentSetting.Value = fileName; } else { currentSetting.Value = setting.Value; } ocmde.SaveChanges(); return(RedirectToAction("Group", "Setting", new { id = currentSetting.Group })); } return(View("Edit", setting)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Setting", "Edit"))); } }
public IActionResult Profile(OctopusCodesMultiVendor.Models.AccountVendor AccountVendor, IFormFile logo) { try { var loginedAccount = ocmde.AccountVendors.SingleOrDefault(v => v.Email.Equals(HttpContext.Session.GetString("email_vendor"))); var currentVendor = ocmde.AccountVendors.SingleOrDefault(a => a.Id == AccountVendor.Id); if (AccountVendor.Email != null && AccountVendor.Email.Length > 0 && loginedAccount.Email != AccountVendor.Email) { if (Exists(AccountVendor.Email)) { ModelState.AddModelError("username", sharedLocalizer["Username_already_exists"]); } } if (AccountVendor.Password != null && AccountVendor.Password.Length != 0 && !PasswordHelper.IsValidPassword(AccountVendor.Password)) { ModelState.AddModelError("Password", sharedLocalizer["Password_validate_message"]); } if (logo != null && logo.Length > 0 && !logo.ContentType.Contains("image")) { ViewBag.errorPhoto = sharedLocalizer["Photo_Invalid"]; return(View("Profile", loginedAccount)); } if (ModelState.IsValid) { if (AccountVendor.Password != null && AccountVendor.Password.Length != 0) { currentVendor.Password = BCrypt.Net.BCrypt.HashPassword(AccountVendor.Password); } //if (logo != null && logo.Length > 0 && logo.ContentType.Contains("image")) //{ // var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetFileName(logo.FileName); // var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/user/images", fileName); // var stream = new FileStream(path, FileMode.Create); // currentVendor.Logo = Path.GetFileName(logo.FileName); //} currentVendor.Email = AccountVendor.Email; currentVendor.FullName = AccountVendor.FullName; currentVendor.Phone = AccountVendor.Phone; currentVendor.Address = AccountVendor.Address; //currentVendor.Username = AccountVendor.Username; ocmde.SaveChanges(); HttpContext.Session.SetString("email_vendor", AccountVendor.Email); return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", AccountVendor)); } } catch (Exception e) { throw; } }
public ActionResult Update(FormCollection fc) { int id = int.Parse(fc["id"]); var vendor = (OctopusCodesMultiVendor.Models.Vendor)SessionPersister.account; var order = ocmde.Orders.Find(id); if (order.VendorId != vendor.Id) { return(View("Error")); } //int paymentId = int.Parse(fc["payment"]); int orderStatusId = int.Parse(fc["orderStatus"]); string trackingId = fc["trackingId"]; var vendorPendingDelivery = order.VendorPendingDeliveries.FirstOrDefault(); vendorPendingDelivery.StartDeliveryDate = DateTime.Now; vendorPendingDelivery.EstimatedDeliveredDate = DateTime.Now.AddDays(DeliveryHelper.GetLatestDays(vendorPendingDelivery.EstimatedDeliveredDays)); vendorPendingDelivery.TrackingId = trackingId; //order.PaymentId = ocmde; order.OrderStatusId = orderStatusId; ocmde.SaveChanges(); return(RedirectToAction("Detail", new { id = order.Id })); }
public IActionResult Edit(int id, Setting setting, IFormFile logo) { try { if (logo != null && logo.Length > 0 && !logo.ContentType.Contains("image")) { ViewBag.errorPhoto = sharedLocalizer["Photo_Invalid"]; return(View("Edit", ocmde.Settings.Find(setting.Id))); } if (ModelState.IsValid) { var currentSetting = ocmde.Settings.Find(setting.Id); if (logo != null && logo.FileName.Length != 0) { var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetFileName(logo.FileName); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/user/images", fileName); var stream = new FileStream(path, FileMode.Create); logo.CopyTo(stream); currentSetting.Value = fileName; } else { currentSetting.Value = setting.Value; } ocmde.SaveChanges(); return(RedirectToAction("Group", "Setting", new { id = currentSetting.Group })); } return(View("Edit", setting)); } catch (Exception e) { throw; } }
// GET: Admin/RajaOngkir public async Task <ActionResult> Index() { client.BaseAddress = new Uri(ocmde.Settings.Find(20).Value); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("key", ocmde.Settings.Find(19).Value); RajaOngkirCityListJson rajaJson = await GetCitiesList("/starter/city"); foreach (Result rst in rajaJson.Rajaongkir.Results) { if (rst.Type == RajaOngkirCityTypeEnum.Kota) { RajaOngkir_CityMapping cityMapping = new RajaOngkir_CityMapping(); cityMapping.Id = Guid.NewGuid(); cityMapping.postal_code = rst.PostalCode; cityMapping.city_id = rst.CityId; cityMapping.city_name = rst.CityName; cityMapping.province = rst.Province; cityMapping.province_id = rst.ProvinceId; cityMapping.type = rst.Type.ToString(); ocmde.RajaOngkir_CityMapping.Add(cityMapping); } ocmde.SaveChanges(); } ViewBag.infoMessage = "Ok"; return(View()); }
public IActionResult Add(MemberShip memberShip) { try { if (ModelState.IsValid) { ocmde.MemberShips.Add(memberShip); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", memberShip)); } catch (Exception e) { throw; } }
public ActionResult Add(MemberShip memberShip) { try { if (ModelState.IsValid) { ocmde.MemberShips.Add(memberShip); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", memberShip)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "MemberShip", "Add"))); } }
public IActionResult Add(ProductViewModel productViewModel) { try { var accountVendor = ocmde.AccountVendors.SingleOrDefault(v => v.Email.Equals(HttpContext.Session.GetString("email_vendor"))); if (ModelState.IsValid) { productViewModel.product.VendorId = accountVendor.Id; productViewModel.product.Views = 0; ocmde.Products.Add(productViewModel.product); ocmde.SaveChanges(); return(RedirectToAction("Index")); } else { productViewModel = new ProductViewModel(); productViewModel.Categories = new System.Collections.Generic.List <SelectListItem>(); var categories = ocmde.Categories.Where(c => c.ParentId == null).ToList(); foreach (var category in categories) { var group = new SelectListGroup { Name = category.Name }; foreach (var subCategory in category.InverseParents) { if (subCategory.VendorId == accountVendor.VendorId || (subCategory.VendorId == null && subCategory.ParentId != null)) { var selectListItem = new SelectListItem() { Text = subCategory.Name, Value = subCategory.Id.ToString(), Group = group }; productViewModel.Categories.Add(selectListItem); } } } return(View("Add", productViewModel)); } } catch (Exception e) { throw; } }
public ActionResult Status(int id) { try { var customer = ocmde.Accounts.SingleOrDefault(a => a.Id == id); customer.Status = !customer.Status; string status = customer.Status ? "Approved" : "Rejected"; string body = string.Format(Resources.Email.Acct_Status_Content, status); EmailHelper.SendEmail(ocmde.Settings.Find(23).Value, customer.Email, Resources.Email.Acct_Status_Subject, body, null); ocmde.SaveChanges(); return(RedirectToAction("Customer", "Account")); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Account", "Status"))); } }
public void UpdateVendorCustomerPoint(int vendorId, int customerId, decimal amount) { decimal point = RewardsPointCalculator.CalculatePoint(amount); RewardsPoint vendorPoint = ocmde.RewardsPoints.FirstOrDefault(a => a.VendorId == vendorId && a.AccountId == null); RewardsPoint customerPoint = ocmde.RewardsPoints.FirstOrDefault(a => a.VendorId == null && a.AccountId == customerId); vendorPoint.AccumulatedPoints += point; vendorPoint.AccumulatedPoints += point; ocmde.SaveChanges(); }
public IActionResult Update(IFormCollection fc) { int id = int.Parse(fc["id"]); int paymentId = int.Parse(fc["payment"]); int orderStatusId = int.Parse(fc["orderStatus"]); var order = ocmde.Orderss.Find(id); order.PaymentId = paymentId; order.OrderStatusId = orderStatusId; ocmde.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Add(CategoryViewModel categoryViewModel) { try { if (ModelState.IsValid) { if (categoryViewModel.category.ParentId == -1) { categoryViewModel.category.ParentId = null; } ocmde.Categories.Add(categoryViewModel.category); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", categoryViewModel)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Category", "Add"))); } }
public IActionResult Add(CategoryViewModel categoryViewModel) { try { if (ModelState.IsValid) { if (categoryViewModel.category.ParentId == -1) { categoryViewModel.category.ParentId = null; } ocmde.Categories.Add(categoryViewModel.category); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", categoryViewModel)); } catch (Exception e) { throw; } }
public IActionResult AddCustumer(Customer custommer) { try { //Valida rut if (!Utils.Rut.ValidaRut(custommer.Rut, custommer.RutDv)) { ModelState.AddModelError("rut", sharedLocalizer["Rut_incorrect"]); } //Valida que no exista //if (addCustomer.Email != null && account.Email.Length > 0) //{ // if (Exists(account.Email)) // { // ModelState.AddModelError("username", sharedLocalizer["Username_already_exists"]); // } //} if (ModelState.IsValid) { //account.IsAdmin = false; custommer.Status = true; custommer.DateCreate = DateTime.Now; ocmde.Customer.Add(custommer); ocmde.SaveChanges(); return(RedirectToAction("Index", "Customer")); } else { return(View("AddCustomer", custommer)); } } catch (Exception e) { throw; } }
public ActionResult Edit(Page page) { try { if (ModelState.IsValid) { var currentPage = ocmde.Pages.Find(page.Id ); currentPage.Plug = page.Plug; currentPage.Title = page.Title; currentPage.Status = page.Status; currentPage.Detail = page.Detail; ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Edit", page)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Page", "Edit"))); } }
public IActionResult Edit(int id, Page page) { try { if (ModelState.IsValid) { var currentPage = ocmde.Pages.Find(page.Id ); currentPage.Plug = page.Plug; currentPage.Title = page.Title; currentPage.Status = page.Status; currentPage.Detail = page.Detail; ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Edit", page)); } catch (Exception e) { throw; } }
public IActionResult Status(int id) { try { var product = ocmde.Products.SingleOrDefault(p => p.Id == id); product.Status = !product.Status; ocmde.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { throw; } }
public IActionResult Add(CategoryViewModel categoryViewModel) { try { if (ModelState.IsValid) { var accountVendor = ocmde.AccountVendors.SingleOrDefault(v => v.Email.Equals(HttpContext.Session.GetString("email_vendor"))); if (categoryViewModel.category.ParentId == -1) { categoryViewModel.category.ParentId = null; } categoryViewModel.category.VendorId = accountVendor.VendorId; ocmde.Categories.Add(categoryViewModel.category); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", categoryViewModel)); } catch (Exception e) { throw; } }
public ActionResult Add(CategoryViewModel categoryViewModel) { try { if (ModelState.IsValid) { var vendor = (OctopusCodesMultiVendor.Models.Vendor)SessionPersister.account; if (categoryViewModel.category.ParentId == -1) { categoryViewModel.category.ParentId = null; } categoryViewModel.category.VendorId = vendor.Id; ocmde.Categories.Add(categoryViewModel.category); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", categoryViewModel)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Category", "Add"))); } }
public ActionResult Status(int id) { try { var product = ocmde.Products.SingleOrDefault(p => p.Id == id); product.Status = !product.Status; ocmde.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Product", "Status"))); } }
public ActionResult Profile(Account account) { try { var loginedAccount = (Account)SessionPersister.account; var currentAccount = ocmde.Accounts.SingleOrDefault(a => a.Id == account.Id); if (account.Username != null && account.Username.Length > 0 && loginedAccount.Username != account.Username) { if (Exists(account.Username)) { ModelState.AddModelError("Username", Resources.Customer.Username_exists); } } if (account.Password != null && account.Password.Length != 0 && !PasswordHelper.IsValidPassword(account.Password)) { ModelState.AddModelError("Password", Resources.Vendor.Password_validate_message); } if (ModelState.IsValid) { if (account.Password != null && account.Password.Length != 0) { currentAccount.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); } currentAccount.Email = account.Email; currentAccount.FullName = account.FullName; currentAccount.Phone = account.Phone; currentAccount.Username = account.Username; ocmde.SaveChanges(); SessionPersister.account = ocmde.Accounts.Find(account.Id); TempData["msg"] = Resources.Customer.Update_Success; return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", account)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Login", "Profile"))); } }
public IActionResult Profile(Users account) { try { var loginedAccount = ocmde.Users.Single(a => a.Username.Equals(HttpContext.Session.GetString("username_admin"))); var currentAccount = ocmde.Users.SingleOrDefault(a => a.Id == account.Id); if (account.Username != null && account.Username.Length > 0 && loginedAccount.Username != account.Username) { if (Exists(account.Username)) { ModelState.AddModelError("Username", sharedLocalizer["Username_already_exists"]); } } if (account.Password != null && account.Password.Length != 0 && !PasswordHelper.IsValidPassword(account.Password)) { ModelState.AddModelError("Password", sharedLocalizer["Password_validate_message"]); } if (ModelState.IsValid) { if (account.Password != null && account.Password.Length != 0) { currentAccount.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); } currentAccount.Email = account.Email; currentAccount.FullName = account.FullName; currentAccount.Phone = account.Phone; currentAccount.Username = account.Username; ocmde.SaveChanges(); HttpContext.Session.SetString("username_admin", account.Username); TempData["msg"] = sharedLocalizer["Update_Success"]; return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", account)); } } catch (Exception e) { throw; } }
public IActionResult Detail(int id) { try { var product = ocmde.Products.Find(id); if (!VendorHelper.checkExpires(product.VendorId)) { return(RedirectToAction("Expires", "Product")); } else { product.Views = product.Views + 1; ocmde.SaveChanges(); ViewBag.product = product; ViewBag.relatedProducts = ocmde.Products.Where(p => p.Id != id && p.CategoryId == product.CategoryId && p.VendorId == product.VendorId).Take(6).ToList(); return(View("Detail")); } } catch (Exception e) { throw; } }
public IActionResult Register(AccountCustomer account) { try { if (account.Email != null && account.Email.Length > 0) { if (Exists(account.Email)) { ModelState.AddModelError("username", sharedLocalizer["Username_already_exists"]); } } if (account.Password != null && account.Password.Length != 0 && !PasswordHelper.IsValidPassword(account.Password)) { ModelState.AddModelError("Password", sharedLocalizer["Password_validate_message"]); } if (ModelState.IsValid) { //account.IsAdmin = false; account.Status = true; account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); ocmde.AccountCustomer.Add(account); ocmde.SaveChanges(); return(RedirectToAction("Index", "Login", new { Area = "customerpanel" })); } else { return(View("Register", account)); } } catch (Exception e) { throw; } }
public ActionResult Profile(OctopusCodesMultiVendor.Models.Vendor vendor, HttpPostedFileBase logo) { try { var loginedAccount = (OctopusCodesMultiVendor.Models.Vendor)SessionPersister.account; var currentVendor = ocmde.Vendors.SingleOrDefault(a => a.Id == vendor.Id); if (vendor.Username != null && vendor.Username.Length > 0 && loginedAccount.Username != vendor.Username) { if (Exists(vendor.Username)) { ModelState.AddModelError("username", Resources.Customer.Username_exists); } } if (vendor.Password != null && vendor.Password.Length != 0 && !PasswordHelper.IsValidPassword(vendor.Password)) { ModelState.AddModelError("Password", Resources.Vendor.Password_validate_message); } if (logo != null && logo.ContentLength > 0 && !logo.ContentType.Contains("image")) { ViewBag.errorPhoto = Resources.Vendor.Photo_Invalid; return(View("Profile", loginedAccount)); } if (ModelState.IsValid) { if (vendor.Password != null && vendor.Password.Length != 0) { currentVendor.Password = BCrypt.Net.BCrypt.HashPassword(vendor.Password); } if (logo != null && logo.ContentLength > 0 && logo.ContentType.Contains("image")) { logo.SaveAs(Path.Combine(Server.MapPath("~/Content/User/Images"), Path.GetFileName(logo.FileName))); currentVendor.Logo = Path.GetFileName(logo.FileName); } currentVendor.Email = vendor.Email; currentVendor.Name = vendor.Name; currentVendor.Phone = vendor.Phone; currentVendor.Username = vendor.Username; if (currentVendor.VendorAddresses.Count <= 0) { VendorAddress acctAddress = vendor.defaultAddress; acctAddress.Id = Guid.NewGuid(); currentVendor.VendorAddresses.Add(acctAddress); } else { VendorAddress acctAddressOriginal = currentVendor.VendorAddresses.FirstOrDefault(); acctAddressOriginal.LineAddress1 = vendor.defaultAddress.LineAddress1; acctAddressOriginal.LineAddress2 = vendor.defaultAddress.LineAddress2; acctAddressOriginal.City = vendor.defaultAddress.City; acctAddressOriginal.ZipCode = vendor.defaultAddress.ZipCode; } if (currentVendor.VendorPaymentInfoes.Count <= 0) { VendorPaymentInfo paymentInfo = new VendorPaymentInfo(); paymentInfo.Id = Guid.NewGuid(); paymentInfo.AccountNo = vendor.vendorPaymentInfo.AccountNo; paymentInfo.Bank = vendor.vendorPaymentInfo.Bank; paymentInfo.Name = vendor.vendorPaymentInfo.Name; paymentInfo.VendorId = vendor.Id; currentVendor.VendorPaymentInfoes.Add(paymentInfo); currentVendor.BankStatus = false; } else { bool isChanged = false; VendorPaymentInfo acctPaymentOriginal = currentVendor.VendorPaymentInfoes.FirstOrDefault(); if (acctPaymentOriginal.AccountNo != vendor.vendorPaymentInfo.AccountNo || acctPaymentOriginal.Bank != vendor.vendorPaymentInfo.Bank || acctPaymentOriginal.Name != vendor.vendorPaymentInfo.Name) { isChanged = true; } acctPaymentOriginal.AccountNo = vendor.vendorPaymentInfo.AccountNo; acctPaymentOriginal.Bank = vendor.vendorPaymentInfo.Bank; acctPaymentOriginal.Name = vendor.vendorPaymentInfo.Name; if (isChanged) { currentVendor.BankStatus = false; string body = string.Format("Vendor:{0} requested to update bank account. Please login to admin to take action", currentVendor.Username); EmailHelper.SendEmail(SettingsHelper.Email_Sender, SettingsHelper.Admin_Email, "Vendor Update Bank Account Request", body, null); ocmde.SaveChanges(); } } ocmde.SaveChanges(); SessionPersister.account = ocmde.Vendors.Find(vendor.Id); return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", vendor)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Login", "Profile"))); } }
public ActionResult Profile(Account account) { try { var loginedAccount = (Account)SessionPersister.account; var currentAccount = ocmde.Accounts.SingleOrDefault(a => a.Id == account.Id); if (account.Username != null && account.Username.Length > 0 && loginedAccount.Username != account.Username) { if (Exists(account.Username)) { ModelState.AddModelError("username", Resources.Customer.Username_exists); } } if (account.Password != null && account.Password.Length != 0 && !PasswordHelper.IsValidPassword(account.Password)) { ModelState.AddModelError("Password", Resources.Vendor.Password_validate_message); } if (ModelState.IsValid) { if (account.Password != null && account.Password.Length != 0) { currentAccount.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); } currentAccount.Email = account.Email; currentAccount.FullName = account.FullName; currentAccount.Phone = account.Phone; currentAccount.Username = account.Username; if (currentAccount.AccountAddresses.Count <= 0) { AccountAddress acctAddress = account.defaultAddress; acctAddress.Id = Guid.NewGuid(); currentAccount.AccountAddresses.Add(acctAddress); } else { AccountAddress acctAddressOriginal = currentAccount.AccountAddresses.FirstOrDefault(); AccountAddress forUpdate = ocmde.AccountAddresses.Find(acctAddressOriginal.Id); forUpdate.City = account.defaultAddress.City; forUpdate.LineAddress1 = account.defaultAddress.LineAddress1; forUpdate.LineAddress2 = account.defaultAddress.LineAddress2; forUpdate.ZipCode = account.defaultAddress.ZipCode; } if (currentAccount.AccountPaymentInfoes.Count <= 0) { AccountPaymentInfo paymentInfo = new AccountPaymentInfo(); paymentInfo.CreditCardNo = account.accountPaymentInfo.CreditCardNo; paymentInfo.ExpiryDate = account.accountPaymentInfo.ExpiryDate; paymentInfo.FullName = account.accountPaymentInfo.FullName; //paymentInfo.Id = Guid.NewGuid(); currentAccount.AccountPaymentInfoes.Add(paymentInfo); } else { AccountPaymentInfo acctPaymentOriginal = currentAccount.AccountPaymentInfoes.FirstOrDefault(); acctPaymentOriginal.CreditCardNo = account.accountPaymentInfo.CreditCardNo; acctPaymentOriginal.ExpiryDate = account.accountPaymentInfo.ExpiryDate; acctPaymentOriginal.FullName = account.accountPaymentInfo.FullName; } ocmde.SaveChanges(); SessionPersister.account = ocmde.Accounts.Find(account.Id); return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", account)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Login", "Profile"))); } }