Example #1
0
        public ActionResult Update(RecordUpdateViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var record = this.records.Update(model.Id, model.Title, model.Description, model.Status, model.StatusDate, model.DateCreated, model.FinishingDate, model.DocumentId);

                if (file != null)
                {
                    var recordFile        = this.recordFiles.Create(model.Id);
                    var extension         = file.FileName.Substring(file.FileName.LastIndexOf("."));
                    var savePath          = $"~/Files/Records/{recordFile.Id % 1000}/{model.Id}-{DateTime.UtcNow.ToShortDateString()}{extension}";
                    var saveDirPathMapped = System.IO.Path.GetDirectoryName(Server.MapPath(savePath));

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

                    file.SaveAs(Server.MapPath(savePath));
                    this.recordFiles.SetPath(recordFile, savePath);

                    this.records.UpdateFile(model.Id, recordFile.Id);
                }

                TempData["Success"] = $"Record with id {record.Id} successfully updated.";
                return(RedirectToAction("Manage", "Areas", new { Area = "Private", id = record.AreaId }));
            }

            return(View(model));
        }
        public ActionResult Update(RecordUpdateViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var record = this.records.Update(model.Id, model.Title, model.Description, model.Status, model.StatusDate, model.DateCreated, model.FinishingDate, model.DocumentId);

                if (file != null)
                {
                    var recordFile = this.recordFiles.Create(model.Id);
                    var extension = file.FileName.Substring(file.FileName.LastIndexOf("."));
                    var savePath = $"~/Files/Records/{recordFile.Id % 1000}/{model.Id}-{DateTime.UtcNow.ToShortDateString()}{extension}";
                    var saveDirPathMapped = System.IO.Path.GetDirectoryName(Server.MapPath(savePath));

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

                    file.SaveAs(Server.MapPath(savePath));
                    this.recordFiles.SetPath(recordFile, savePath);

                    this.records.UpdateFile(model.Id, recordFile.Id);
                }

                TempData["Success"] = $"Record with id {record.Id} successfully updated.";
                return RedirectToAction("Manage", "Areas", new { Area = "Private", id = record.AreaId });
            }

            return View(model);
        }