Ejemplo n.º 1
0
 public AddCustomerViewModel MapCustomerToCustomerVM(Customer lstcust)
 {
     AddCustomerViewModel addCustomerViewModel = new AddCustomerViewModel();
     AddCustomerViewModel result;
     if (lstcust != null)
     {
         addCustomerViewModel.customerId = lstcust.CustomerId;
         addCustomerViewModel.CustomerSurName = lstcust.CustomerSurname;
         addCustomerViewModel.CustomerName = lstcust.CustomerName;
         addCustomerViewModel.FirmName = lstcust.CustomerFirmname;
         if (lstcust.CustomerFirmname == null)
         {
             addCustomerViewModel.FirmName = "";
         }
         else
         {
             addCustomerViewModel.FirmName = lstcust.CustomerFirmname;
         }
         addCustomerViewModel.MobileNumber = lstcust.MobileNo.ToString();
         addCustomerViewModel.Address = lstcust.Address;
         addCustomerViewModel.CustomerImageName = lstcust.CustomerImageName;
         addCustomerViewModel.CustomerImagePath = lstcust.CustomerImagePath;
         result = addCustomerViewModel;
     }
     else
     {
         result = null;
     }
     return result;
 }
Ejemplo n.º 2
0
 public Customer MapNewCustomerVMToCustomer(AddCustomerViewModel addcustvm)
 {
     return new Customer
     {
         CustomerSurname = addcustvm.CustomerSurName,
         CustomerName = addcustvm.CustomerName,
         MobileNo = new decimal?(decimal.Parse(addcustvm.MobileNumber)),
         Address = addcustvm.Address,
         CustomerFirmname = addcustvm.FirmName,
         CustomerImageName = addcustvm.CustomerImageName,
         CustomerImagePath = addcustvm.CustomerImagePath,
         UserId = addcustvm.UserId
     };
 }
Ejemplo n.º 3
0
        public List<AddCustomerViewModel> MaplstCustomerTolstCustomerVM(List<Customer> lstcust)
        {
            List<AddCustomerViewModel> listacvm = new List<AddCustomerViewModel>();
            if (lstcust.Count > 0)
            {
                foreach (Customer current in lstcust)
                {
                    AddCustomerViewModel acvm = new AddCustomerViewModel();
                    acvm.customerId = current.CustomerId;

                    acvm.CustomerName = current.CustomerName;

                    if (current.CustomerSurname == null)
                    {
                        acvm.CustomerSurName = "";
                    }
                    else
                    {
                        acvm.CustomerSurName = current.CustomerSurname;
                    }
                    if (current.CustomerFirmname == null)
                    {
                        acvm.FirmName = "";
                    }
                    else
                    {
                        acvm.FirmName = current.CustomerFirmname;
                    }

                    acvm.MobileNumber = current.MobileNo.ToString();
                    acvm.Address = current.Address;
                    acvm.CustomerImageName = current.CustomerImageName;
                    acvm.CustomerImagePath = current.CustomerImagePath;
                    listacvm.Add(acvm);
                }
            }
            return listacvm;
        }
Ejemplo n.º 4
0
        public ActionResult AddCustomer(AddCustomerViewModel acvm, HttpPostedFileBase ProfImage)
        {
            if (Session["UserId"] != null)
            {
                acvm.UserId = int.Parse(Session["UserId"].ToString());
                if (ModelState.IsValid == true)
                {
                    if (ProfImage != null && ProfImage.ContentLength > 0)
                    {
                        string text = ProfImage.FileName;
                        text = text.Substring(text.LastIndexOf("."));
                        if (!(text == ".jpg") && !(text == ".jpeg") && !(text == ".png"))
                        {

                            //HomeController.<AddCustomer>o__SiteContainer6.<>p__Site7 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "Message", typeof(HomeController), new CSharpArgumentInfo[]
                            //{
                            //    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                            //    CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                            //}));
                            ViewBag.Message = "Invalid Image.";

                            //HomeController.<AddCustomer>o__SiteContainer6.<>p__Site7.Target(HomeController.<AddCustomer>o__SiteContainer6.<>p__Site7, base.get_ViewBag(), "Invalid Image.");
                            return View();

                        }
                        string text2 = Path.GetFileName(ProfImage.FileName);
                        string fileName = ProfImage.FileName;
                        text2 = text2.Substring(0, text2.LastIndexOf(".") - 1);
                        text2 = text2 + DateTime.Now.Ticks.ToString() + text;
                        string filename = Path.Combine(Server.MapPath("~/CustomerImage/"), text2);
                        ProfImage.SaveAs(filename);
                        string customerImagePath = "~/CustomerImage/" + text2;
                        acvm.CustomerImageName = acvm.CustomerSurName + " " + acvm.CustomerName;
                        acvm.CustomerImagePath = customerImagePath;

                    }
                    else
                    {
                        acvm.CustomerImageName = "No Image";
                        acvm.CustomerImagePath = "~/Content/images/no-Image.png";
                    }
                    int num = this._db.InsertNewCustomer(usrMaps.MapNewCustomerVMToCustomer(acvm));
                    if (num == 1)
                    {
                        //if (HomeController.<AddCustomer>o__SiteContainer6.<>p__Site8 == null)
                        //{
                        //    HomeController.<AddCustomer>o__SiteContainer6.<>p__Site8 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "Message", typeof(HomeController), new CSharpArgumentInfo[]
                        //    {
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                        //    }));
                        //}
                        //HomeController.<AddCustomer>o__SiteContainer6.<>p__Site8.Target(HomeController.<AddCustomer>o__SiteContainer6.<>p__Site8, base.get_ViewBag(), "Customer Added Successfully");
                        @ViewBag.Message = "Customer Added Successfully";
                        return RedirectToAction("ViewCustomers", "Home");
                        //result = base.RedirectToAction("ViewCustomers");
                    }
                    else
                    {
                        //if (HomeController.<AddCustomer>o__SiteContainer6.<>p__Site9 == null)
                        //{
                        //    HomeController.<AddCustomer>o__SiteContainer6.<>p__Site9 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "error", typeof(HomeController), new CSharpArgumentInfo[]
                        //    {
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                        //    }));
                        //}
                        //HomeController.<AddCustomer>o__SiteContainer6.<>p__Site9.Target(HomeController.<AddCustomer>o__SiteContainer6.<>p__Site9, base.get_ViewBag(), "Error Occured while Inserting New Customer");
                        //result = base.View();
                        @ViewBag.error = "Error Occured while Inserting New Customer";
                        return View();
                    }

                }
                else
                {
                    return View();
                }
            }
            else
            {
                return RedirectToAction("Home", "LogIn");
            }
        }
Ejemplo n.º 5
0
        public ActionResult EditCustomer(int id, AddCustomerViewModel acvm, HttpPostedFileBase ProfImage)
        {
            if (Session["UserId"] != null)
            {
                if (ModelState.IsValid == true)
                {
                    if (ProfImage != null && ProfImage.ContentLength > 0)
                    {
                        string text = ProfImage.FileName;
                        text = text.Substring(text.LastIndexOf("."));
                        if (!(text == ".jpg") && !(text == ".jpeg") && !(text == ".png"))
                        {
                            //if (HomeController.<EditCustomer>o__SiteContainera.<>p__Siteb == null)
                            //{
                            //    HomeController.<EditCustomer>o__SiteContainera.<>p__Siteb = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "Message", typeof(HomeController), new CSharpArgumentInfo[]
                            //    {
                            //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                            //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                            //    }));
                            //}
                            //HomeController.<EditCustomer>o__SiteContainera.<>p__Siteb.Target(HomeController.<EditCustomer>o__SiteContainera.<>p__Siteb, base.get_ViewBag(), "Invalid Image.");
                            ViewBag.Message = "Invalid Image.";
                            return View(acvm);

                        }
                        string text2 = Path.GetFileName(ProfImage.FileName);
                        string fileName = ProfImage.FileName;
                        text2 = text2.Substring(0, text2.LastIndexOf(".") - 1);
                        text2 = text2 + DateTime.Now.Ticks.ToString() + text;
                        string filename = Path.Combine(Server.MapPath("~/CustomerImage/"), text2);
                        ProfImage.SaveAs(filename);
                        string customerImagePath = "~/CustomerImage/" + text2;
                        acvm.CustomerImageName = acvm.CustomerSurName + " " + acvm.CustomerName;
                        acvm.CustomerImagePath = customerImagePath;
                    }
                    int num = this._db.UpdateCustomer(acvm, id);
                    if (num == 1)
                    {
                        //if (HomeController.<EditCustomer>o__SiteContainera.<>p__Sitec == null)
                        //{
                        //    HomeController.<EditCustomer>o__SiteContainera.<>p__Sitec = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "Message", typeof(HomeController), new CSharpArgumentInfo[]
                        //    {
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                        //    }));
                        //}
                        //HomeController.<EditCustomer>o__SiteContainera.<>p__Sitec.Target(HomeController.<EditCustomer>o__SiteContainera.<>p__Sitec, base.get_ViewBag(), "Customer Updated Successfully");
                        //result = base.View(acvm);
                        ViewBag.Message = "Customer Updated Successfully";
                        return View(acvm);
                    }
                    else
                    {
                        //if (HomeController.<EditCustomer>o__SiteContainera.<>p__Sited == null)
                        //{
                        //    HomeController.<EditCustomer>o__SiteContainera.<>p__Sited = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "error", typeof(HomeController), new CSharpArgumentInfo[]
                        //    {
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                        //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                        //    }));
                        //}
                        //HomeController.<EditCustomer>o__SiteContainera.<>p__Sited.Target(HomeController.<EditCustomer>o__SiteContainera.<>p__Sited, base.get_ViewBag(), "Error Occured while Updating Customer");
                        ViewBag.Message = "Error Occured while Updating Customer";
                        return View(acvm);
                    }
                }
                else
                {
                    return View(acvm);
                }
            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }
Ejemplo n.º 6
0
 public int UpdateCustomer(AddCustomerViewModel acvm, int CustId)
 {
     Customer customer = (
         from a in this.db.Customers
         where a.CustomerId == CustId
         select a).FirstOrDefault<Customer>();
     int result;
     try
     {
         customer.CustomerFirmname = acvm.FirmName;
         customer.CustomerName = acvm.CustomerName;
         customer.CustomerSurname = acvm.CustomerSurName;
         customer.MobileNo = new decimal?(decimal.Parse(acvm.MobileNumber));
         customer.Address = acvm.Address;
         if (acvm.CustomerImagePath != null && acvm.CustomerImagePath != "")
         {
             customer.CustomerImageName = acvm.CustomerImageName;
             customer.CustomerImagePath = acvm.CustomerImagePath;
         }
         this.db.SaveChanges();
         result = 1;
     }
     catch
     {
         result = 0;
     }
     return result;
 }