Exemplo n.º 1
0
        public AllMaterial MapEditMaterialVmToEditMaterial(EditMaterialViewModel addvm)
        {
            AllMaterial allMaterial = new AllMaterial();
            allMaterial.MaterialCode = addvm.MaterialCode;
            allMaterial.Datetime = new DateTime?(DateTime.Now);
            allMaterial.MaterialId = addvm.MaterialId;
            if (addvm.MaterialImage != null)
            {
                allMaterial.MaterialImagePath = addvm.MaterialImagePath;
            }

            return allMaterial;
        }
Exemplo n.º 2
0
        public ActionResult EditMaterial(EditMaterialViewModel emvm, HttpPostedFileBase MaterialImage)
        {
            if (Session["UserId"] != null)
            {
                PragatiEntities db = new PragatiEntities();

                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;
                    emvm.MaterialImagePath = materialImagePath;

                    AllMaterial allMaterial = db.AllMaterials.Where(a => a.MaterialId == emvm.MaterialId).FirstOrDefault();
                    allMaterial.MaterialCode = emvm.MaterialCode;
                    allMaterial.Datetime = new DateTime?(DateTime.Now);
                    allMaterial.MaterialId = emvm.MaterialId;
                    if (emvm.MaterialImage != null)
                    {

                        allMaterial.MaterialImagePath = emvm.MaterialImagePath;
                    }
                    try
                    {
                        db.SaveChanges();
                        ViewBag.success = "Material Updated Successfully";
                        return View(emvm);
                    }
                    catch
                    {
                        ViewBag.Message = "Error occured Please try Again";
                        return View(emvm);
                    }

                }
                else
                {

                    ViewBag.Message = "Invalid Image.";
                    return View(emvm);
                }

            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }
Exemplo n.º 3
0
        public ActionResult EditMaterial(int id)
        {
            if (Session["UserId"] != null)
            {
                PragatiEntities db = new PragatiEntities();
                var data = db.AllMaterials.Where(a => a.MaterialId == id).FirstOrDefault();
                EditMaterialViewModel edtmvm = new EditMaterialViewModel();
                edtmvm.MaterialId = id;
                edtmvm.MaterialCode = data.MaterialCode;
                edtmvm.MaterialImagePath = data.MaterialImagePath;
                var materialtype = db.MaterialTypes.Where(a => a.MaterialTypeId == data.MaterialTypeId).FirstOrDefault();
                edtmvm.MaterialName = materialtype.MaterialName;
                if (materialtype.MaterialTypeId == 3)
                {
                    var submaterialtype = db.Sub_Kasab.Where(a => a.MaterialTypeId == data.MaterialTypeId).FirstOrDefault();
                    edtmvm.SubMaterialName = submaterialtype.Name;
                    edtmvm.SubMaterialId = submaterialtype.Sub_KasabId;
                }
                return View(edtmvm);

            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }