Esempio n. 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            JewelryMachines JewelryMachine = db.JewelryMachines.Find(id);

            db.JewelryMachines.Remove(JewelryMachine);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 public ActionResult Edit(JewelryMachines JewelryMachines)
 {
     if (ModelState.IsValid)
     {
         db.Entry(JewelryMachines).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "ContactPersonName", JewelryMachines.CompanyId);
     return(View(JewelryMachines));
 }
Esempio n. 3
0
        // GET: JewelryMachine/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            JewelryMachines JewelryMachine = db.JewelryMachines.Find(id);

            if (JewelryMachine == null)
            {
                return(HttpNotFound());
            }
            return(View(JewelryMachine));
        }
Esempio n. 4
0
        // GET: JewelryMachine/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            JewelryMachines JewelryMachine = db.JewelryMachines.Find(id);

            if (JewelryMachine == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "ContactPersonName", JewelryMachine.CompanyId);
            return(View(JewelryMachine));
        }
Esempio n. 5
0
        public ActionResult Create(JewelryMachinesViewModel machines, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                JewelryMachines machine        = new JewelryMachines();
                var             claimsIdentity = User.Identity as ClaimsIdentity;

                Mapper.Map(machines, machine);

                UserInfo  userInfo = new UserInfo(db);
                Companies company  = userInfo.getLoggedCompanyId(claimsIdentity);
                machine.Companies = company;

                db.JewelryMachines.Add(machine);
                db.SaveChanges();

                //save images
                SaveImages(files, company, machine);

                return(RedirectToAction("Index"));
            }

            return(View(machines));
        }
Esempio n. 6
0
        public ActionResult SaveImages(IEnumerable <HttpPostedFileBase> files, Companies company, JewelryMachines jewelryMachine)
        {
            // The Name of the Upload component is "files"
            if (files != null)
            {
                int i = 1;
                foreach (var file in files)
                {
                    // Some browsers send file names with full path.
                    // We are only interested in the file name.
                    var fileName     = Path.GetFileName(file.FileName);
                    var webPath      = "DataImages/JewelryMachines/" + company.Id + "/JewelryMachine" + jewelryMachine.Id;
                    var physicalPath = Server.MapPath("/") + webPath;

                    if (!System.IO.Directory.Exists(physicalPath))
                    {
                        System.IO.Directory.CreateDirectory(physicalPath);
                    }

                    // The files are not actually saved in this demo
                    physicalPath = physicalPath + "/" + i + "." + file.FileName.Split('.')[1];
                    webPath      = webPath + "/" + i + "." + file.FileName.Split('.')[1];

                    file.SaveAs(physicalPath);
                    //physicalPath = physicalPath.Replace(" ", "%20");
                    JewelryMachinesImageURL imageURL = new JewelryMachinesImageURL();
                    imageURL.ImageURL = webPath;
                    jewelryMachine.JewelryMachinesImageURL.Add(imageURL);
                    i++;
                }
            }


            db.SaveChanges();

            // Return an empty string to signify success
            return(Content(""));
        }