public ActionResult Add(ExpenseModel expensemodel) { try { if (ModelState.IsValid) { Documents Documents = new Documents(); if (_IExpense.CheckIsDateAlreadyUsed(expensemodel.FromDate, expensemodel.ToDate, Convert.ToInt32(Session["UserID"]))) { ModelState.AddModelError("", "Date you have choosen is already used !"); return View(expensemodel); } else { expensemodel.ExpenseID = 0; expensemodel.CreatedOn = DateTime.Now; expensemodel.ExpenseStatus = 1; expensemodel.UserID = Convert.ToInt32(Session["UserID"]); var ExpenseID = _IExpense.AddExpense(expensemodel); if (ExpenseID > 0) { if (Request.Files != null) { foreach (string requestFile in Request.Files) { HttpPostedFileBase file = Request.Files[requestFile]; { if (file.ContentLength > 0) { string _FileName = Path.GetFileName(file.FileName); Documents.DocumentID = 0; Documents.DocumentName = _FileName; using (var binaryReader = new BinaryReader(file.InputStream)) { byte[] FileSize = binaryReader.ReadBytes(file.ContentLength); Documents.DocumentBytes = FileSize; Documents.CreatedOn = DateTime.Now; } Documents.ExpenseID = ExpenseID; Documents.UserID = Convert.ToInt32(Session["UserID"]); if (Path.GetExtension(file.FileName) == ".zip" || Path.GetExtension(file.FileName) == ".rar") { Documents.DocumentType = "Multi"; } else { Documents.DocumentType = "Single"; } _IDocument.AddDocument(Documents); } TempData["ExpenseMessage"] = "Data Saved Successfully"; } } } _IExpense.InsertExpenseAuditLog(InsertExpenseAudit(ExpenseID, 1)); } else { ModelState.AddModelError("", "Please Upload Required Attachments"); return View(expensemodel); } ModelState.Clear(); return View(new ExpenseModel()); } } return View(new ExpenseModel()); } catch (Exception) { throw; } }