예제 #1
0
        public string EditCustomer(CustomerViewModel Model)
        {
            string msgClient;

            try
            {
                if (ModelState.IsValid)
                {
                    var enditedCustomerValue = new LMS_Datas.Customer
                    {
                        Active     = true,
                        CustomerId = Model.CustomerId,
                        Address    = Model.Address,
                        EmailId    = Model.EmailId,
                        dob        = Model.dob,
                        Name       = Model.CustomerName,
                        MobileNo   = Model.MobileNo
                    };

                    entity.Customers.Attach(enditedCustomerValue);
                    entity.Entry(enditedCustomerValue).Property(x => x.cityId).IsModified    = false;
                    entity.Entry(enditedCustomerValue).Property(x => x.stateId).IsModified   = false;
                    entity.Entry(enditedCustomerValue).Property(x => x.dob).IsModified       = false;
                    entity.Entry(enditedCustomerValue).Property(x => x.gender).IsModified    = false;
                    entity.Entry(enditedCustomerValue).Property(x => x.countryId).IsModified = false;
                    entity.Entry(enditedCustomerValue).Property(x => x.Name).IsModified      = true;
                    entity.Entry(enditedCustomerValue).Property(x => x.EmailId).IsModified   = true;
                    entity.Entry(enditedCustomerValue).Property(x => x.MobileNo).IsModified  = true;
                    //entity.Entry(enditedValue).State = EntityState.Modified;
                    entity.SaveChanges();

                    int?loginid = (from loginId in entity.Logins where loginId.UserId == Model.CustomerId select loginId.UserId).FirstOrDefault();
                    var enditedCustomerLoginValue = new LMS_Datas.Login
                    {
                        UserId   = Model.CustomerId,
                        UserName = Model.UserName,
                        Password = Model.Password,
                        Activate = "true",
                        Role     = "Customer"
                    };

                    entity.Logins.Attach(enditedCustomerLoginValue);
                    entity.Entry(enditedCustomerLoginValue).State = EntityState.Modified;
                    entity.SaveChanges();
                    msgClient = "Saved Successfully";
                }
                else
                {
                    msgClient = "Validation data not successfully";
                }
            }
            catch (Exception ex)
            {
                msgClient = "Error in Retriving Data";
            }
            return(msgClient);
        }
예제 #2
0
 public ActionResult Index(CustomerViewModel model, FormCollection form, HttpPostedFileBase files)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string statusDDLValue = form["Statusddl"].ToString();
             string genderDDLValue = form["genderddl"].ToString();
             using (var context = new LoyaltyManagementSystemEntities())
             {
                 var customer = new LMS_Datas.Customer()
                 {
                     Name      = model.CustomerName,
                     Address   = model.Address,
                     dob       = model.dob,
                     EmailId   = model.EmailId,
                     MobileNo  = model.MobileNo,
                     gender    = genderDDLValue,
                     countryId = model.countryId,
                     stateId   = model.stateId,
                     cityId    = model.cityId,
                     Active    = Boolean.Parse(statusDDLValue)
                 };
                 context.Customers.Add(customer);
                 context.SaveChanges();
                 customer.CustomerId = customer.CustomerId;
                 var CustomerLogin = new LMS_Datas.Login()
                 {
                     UserId   = customer.CustomerId,
                     UserName = model.UserName,
                     Password = model.Password,
                     Activate = "true",
                     Role     = "Customer"
                 };
                 context.Logins.Add(CustomerLogin);
                 context.SaveChanges();
                 if (files.FileName != null)
                 {
                     var    ext    = Path.GetExtension(files.FileName);
                     string myfile = customer.CustomerId + ext;
                     var    path   = Path.Combine(Server.MapPath("~/Images/CustomerProfile"), myfile);
                     files.SaveAs(path);
                 }
             }
         }
         ViewBag.CountryDd = new SelectList(entity.countries.Where(models => models.Active == true), "countryId", "countryName");
         ViewBag.alert     = "Success";
         return(View());
     }
     catch (Exception e1)
     {
         ViewBag.CountryDd = new SelectList(entity.countries.Where(models => models.Active == true), "countryId", "countryName");
         ViewBag.alert     = "Error";
         return(View());
     }
 }