예제 #1
0
 public AllMaterial MapAllMaterialVmToAllMaterial(AddMaterialViewModel addvm)
 {
     AllMaterial allMaterial = new AllMaterial();
     allMaterial.MaterialCode = addvm.MaterialCode;
     allMaterial.Datetime = new DateTime?(DateTime.Now);
     if (addvm.MaterialImage != null)
     {
         allMaterial.MaterialImagePath = addvm.MaterialImagePath;
     }
     else
     {
         allMaterial.MaterialImagePath = "No Image";
     }
     allMaterial.MaterialTypeId = new int?(addvm.MaterialId);
     if (addvm.MaterialId == 3)
     {
         allMaterial.Sub_KasabId = new int?(addvm.SubMaterialId);
     }
     if (addvm.MaterialId == 5)
     {
         allMaterial.Price = new double?((double)addvm.Price);
     }
     if (addvm.MaterialId == 6)
     {
         allMaterial.Price = new double?((double)addvm.Price);
     }
     if (addvm.MaterialId == 7)
     {
         allMaterial.Price = new double?((double)addvm.Price);
     }
     return allMaterial;
 }
예제 #2
0
        public ActionResult AddNewMaterial(AddMaterialViewModel addmvm, HttpPostedFileBase MaterialImage)
        {
            if (Session["UserId"] != null)
            {

                if (MaterialImage != null)
                {
                    string text = MaterialImage.FileName;
                    text = text.Substring(text.LastIndexOf("."));
                    if (text == ".jpg" || text == ".jpeg" || text == ".png" || text == ".JPG" || text == ".JPEG" || text == ".PNG")
                    {
                        string text2 = Path.GetFileName(MaterialImage.FileName);
                        string fileName = MaterialImage.FileName;
                        text2 = text2.Substring(0, text2.LastIndexOf(".") - 1);
                        text2 = text2 + DateTime.Now.Ticks.ToString() + text;
                        string filename = Path.Combine(Server.MapPath("~/MaterialImage/"), text2);
                        MaterialImage.SaveAs(filename);
                        string materialImagePath = "~/MaterialImage/" + text2;
                        addmvm.MaterialImagePath = materialImagePath;
                        int num = _db.insertNewMaterial(usrMaps.MapAllMaterialVmToAllMaterial(addmvm));
                        if (num == 1)
                        {
                            //if (HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site10 == null)
                            //{
                            //    HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site10 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "success", typeof(HomeController), new CSharpArgumentInfo[]
                            //    {
                            //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                            //        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
                            //    }));
                            //}
                            //HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site10.Target(HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site10, base.get_ViewBag(), "Material Added Successfully");
                            ViewBag.success = "Material Added Successfully";
                            return View();
                        }
                        else
                        {
                            //if (HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site11 == null)
                            //{
                            //    HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site11 = 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.<AddNewMaterial>o__SiteContainere.<>p__Site11.Target(HomeController.<AddNewMaterial>o__SiteContainere.<>p__Site11, base.get_ViewBag(), "Error occured Please try Again");
                            ViewBag.Message = "Error occured Please try Again";
                            return View();
                        }
                    }
                    else
                    {
                        //if (HomeController.<AddNewMaterial>o__SiteContainere.<>p__Sitef == null)
                        //{
                        //    HomeController.<AddNewMaterial>o__SiteContainere.<>p__Sitef = 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.<AddNewMaterial>o__SiteContainere.<>p__Sitef.Target(HomeController.<AddNewMaterial>o__SiteContainere.<>p__Sitef, base.get_ViewBag(), "Invalid Image.");
                        ViewBag.Message = "Invalid Image.";
                        return View();
                    }
                }
                else
                {
                    addmvm.MaterialImage = "No Image";
                    addmvm.MaterialImagePath = "~/Content/images/no-Image.png";
                    int num = _db.insertNewMaterial(usrMaps.MapAllMaterialVmToAllMaterial(addmvm));
                    if (num == 1)
                    {
                        ViewBag.success = "Material Added Successfully";
                        return View();
                    }
                    else
                    {
                        ViewBag.Message = "Error occured Please try Again";
                        return View();
                    }
                }
            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }