Example #1
0
        public ActionResult EditDetailMovement(int?id)
        {
            DetailProgramViewModel prog         = _context.DetailPrograms.FirstOrDefault(z => z.Id == id);
            AddDetailProgram       editMovement = new AddDetailProgram();

            editMovement.Deskripsi = prog.Deskripsi;
            editMovement.Langkah   = prog.Langkah;
            editMovement.ProgramId = prog.ProgramId;
            editMovement.Id        = prog.Id;
            return(PartialView("_editDetailMovement", editMovement));
        }
Example #2
0
        public ActionResult AddDetailMovement(AddDetailProgram model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    DetailProgramViewModel prog = new DetailProgramViewModel();
                    prog.Langkah   = model.Langkah;
                    prog.Deskripsi = model.Deskripsi;
                    prog.ProgramId = model.ProgramId;



                    if (model.FotoGerakan != null)
                    {
                        if (model.FotoGerakan.ContentLength > 0)
                        {
                            var fileName   = Path.GetFileName(model.FotoGerakan.FileName);
                            var guid       = Guid.NewGuid().ToString();
                            var folderPath = Server.MapPath("~/uploads/" + model.Id);
                            if (!Directory.Exists(folderPath))
                            {
                                Directory.CreateDirectory(folderPath);
                            }
                            var path = Path.Combine(folderPath, fileName);
                            model.FotoGerakan.SaveAs(path);
                            string   fl        = path.Substring(path.LastIndexOf("\\"));
                            string[] split     = fl.Split('\\');
                            string   newpath   = split[1];
                            string   imagepath = "/uploads/" + model.Id + "/" + newpath;
                            prog.FotoGerakan = imagepath;
                        }
                    }
                    _context.DetailPrograms.Add(prog);
                    _context.SaveChanges();
                    TempData["Success"] = "Shop Added Successfully!";
                }
                catch (Exception e)
                {
                    TempData["Error"] = e.Message;
                }
            }
            return(RedirectToAction("DetailMovement", "Movement", new { id = model.ProgramId }));
        }