public ActionResult Edit(CustomerDocumentModel model, HttpPostedFileBase[] documentContent, FormCollection collection)
        {
            try
            {
                var oldCustomerDocument = _service.GetDetails(model.CustomerDocument.Id);
                oldCustomerDocument.CustomerId     = model.CustomerDocument.CustomerId;
                oldCustomerDocument.DocumentTypeId = model.CustomerDocument.DocumentTypeId;
                var _oldDocumentContent = oldCustomerDocument.DocumentContent;

                foreach (HttpPostedFileBase file in documentContent)
                {
                    //file save
                    if (file != null && file.ContentLength > 0)
                    {
                        string fileName   = Path.GetFileName(file.FileName);
                        string folderPath = Helpers.Constants.GetCustomerDocumentFolder(oldCustomerDocument.Id);

                        //string path = Path.Combine(folderPath, fileName);
                        var path = FileService.GetFullPath(folderPath, fileName);
                        file.SaveAs(path);

                        //Delete the old fileName
                        string fullPath = Path.Combine(folderPath + _oldDocumentContent);
                        FileService.DeleteFile(fullPath);
                    }
                }
                _service.Update(oldCustomerDocument);

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View());
            }
        }
Example #2
0
 // PUT: api/CustomerDocument/5
 public IHttpActionResult Put([FromBody] CustomerDocument model)
 {
     _service.Update(model);
     return(Ok(model));
 }