public ActionResult Create() { var transtypes = new SelectList(new[] { new { ID = "Cr", trans = "Credit" }, new { ID = "Dr", trans = "Debit" }, }, "ID", "trans", 1); ViewBag.businessType = db.BusinessTypes.ToList(); ViewBag.country = db.CountryMasters.ToList(); ViewBag.city = db.CityMasters.ToList(); ViewBag.location = db.LocationMasters.ToList(); ViewBag.currency = db.CurrencyMasters.ToList(); ViewBag.employee = db.EmployeeMasters.ToList(); ViewBag.roles = db.RoleMasters.ToList(); int branchid = Convert.ToInt32(Session["CurrentBranchID"].ToString()); PickupRequestDAO doa = new PickupRequestDAO(); ViewBag.CustomerNo = doa.GetMaxCustomerCode(branchid); CustmorVM obj = new CustmorVM(); obj.RoleID = 13; obj.Password = doa.RandomPassword(6); return(View(obj)); }
public ActionResult Create(CustmorVM c) { string locationname = c.LocationName; string country = c.CountryName; string city = c.CityName; CustomerMaster obj = new CustomerMaster(); PickupRequestDAO _dao = new PickupRequestDAO(); int max = (from d in db.CustomerMasters orderby d.CustomerID descending select d.CustomerID).FirstOrDefault(); int accompanyid = Convert.ToInt32(Session["CurrentCompanyID"].ToString()); int branchid = Convert.ToInt32(Session["CurrentBranchID"].ToString()); obj.CustomerID = max + 1; obj.AcCompanyID = accompanyid; obj.CustomerCode = _dao.GetMaxCustomerCode(branchid); // c.CustomerCode; obj.CustomerName = c.CustomerName; obj.CustomerType = c.CustomerType; obj.ReferenceCode = c.ReferenceCode; obj.ContactPerson = c.ContactPerson; obj.Address1 = c.Address1; obj.Address2 = c.Address2; obj.Address3 = c.Address3; obj.Phone = c.Phone; obj.Mobile = c.Mobile; obj.Fax = c.Fax; obj.Email = c.Email; obj.WebSite = c.Website; obj.CountryID = 1;; // c.CountryID; obj.CityID = 19; // c.CityID; obj.LocationID = 7; // c.LocationID; obj.CountryName = c.CountryName; obj.CityName = c.CityName; obj.LocationName = c.LocationName; obj.CurrencyID = c.CurrenceyID; obj.StatusActive = c.StatusActive; obj.CreditLimit = c.CreditLimit; obj.StatusTaxable = c.StatusTaxable; obj.EmployeeID = c.EmployeeID; obj.statusCommission = c.StatusCommission; obj.CourierServiceID = c.CourierServiceID; obj.BranchID = Convert.ToInt32(Session["CurrentBranchID"].ToString()); obj.CustomerUsername = c.CustomerUsername; //obj.Password = c.Password; obj.Password = _dao.RandomPassword(6); obj.BusinessTypeId = c.BusinessTypeId; obj.Referal = c.Referal; obj.OfficeOpenTime = c.OfficeTimeFrom; obj.OfficeCloseTime = c.OfficeTimeTo; UserRegistration u = new UserRegistration(); UserRegistration x = (from a in db.UserRegistrations where a.UserName == c.Email select a).FirstOrDefault(); if (x == null) { int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault(); u.UserID = max1 + 1; u.UserName = c.Email; u.EmailId = c.Email; u.Password = obj.Password; u.Phone = c.Phone; u.IsActive = true; u.RoleID = c.RoleID; } if (ModelState.IsValid) { try { db.CustomerMasters.Add(obj); db.SaveChanges(); if (c.EmailNotify == true) { EmailDAO _emaildao = new EmailDAO(); _emaildao.SendCustomerEmail(c.Email, c.CustomerName, obj.Password); } } 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); } } } try { db.UserRegistrations.Add(u); 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); } } } TempData["SuccessMsg"] = "You have successfully added Customer."; return(RedirectToAction("Index")); } return(View()); }