public async Task <ActionResult> Create(int id) { try { ViewBag.User_Id = HttpContext.Session.GetString("User_Id"); ViewBag.Company_Id = HttpContext.Session.GetString("Company_Id"); ViewBag.UserName = HttpContext.Session.GetString("UserName"); ViewBag.FullName = HttpContext.Session.GetString("ContactName"); if (quotationService.CheckQuotationLimit(Convert.ToInt32(HttpContext.Session.GetString("Company_Id"))) == false) { TempData["message"] = "Quotation Limitation per week is exceed. please contact admin to upgrade your account."; return(RedirectToAction("Index")); } var result = await quotationService.InitialLoadByRfqId(id); result.Document = new VmDocumentItem(); result.Document.ContactPersonName = HttpContext.Session.GetString("UserName"); result.Document.DocumentStatus_Id = Constants_CodeTable.Code_Quotation_Draft; result.Document.DocumentType_Id = Constants_CodeTable.Code_Quotation; result.Document.Company_Id = Convert.ToInt32(HttpContext.Session.GetString("Company_Id")); result.Document.ContactPersonName = HttpContext.Session.GetString("ContactName"); result.Document.CreatedBy = result.Document.UpdatedBy = result.CreatedBy = result.UpdatedBy = HttpContext.Session.GetString("UserName"); result.Document.DocumentUser = new List <VmDocumentUserItem>(); var documentUser = new VmDocumentUserItem { User_Id = Convert.ToInt32(HttpContext.Session.GetString("User_Id")), Role_Id = Convert.ToInt32(Constants.QuotationDefaultRoleId) }; result.Document.DocumentUser.Add(documentUser); result.Document.DocumentActivityList = new List <VmDocumentActivityItem>(); var DocumentActivity = new VmDocumentActivityItem() { User_Id = Convert.ToInt32(HttpContext.Session.GetString("User_Id")), IsRfq = false, Action = "Create", }; result.Document.DocumentActivityList.Add(DocumentActivity); var resultSaving = await quotationService.SaveQuotation(result); if (resultSaving.IsSuccess) { return(RedirectToAction("Edit", new { id = resultSaving.MessageToUser })); } else { TempData["ErrorMessage"] = "Error on updating quotation."; return(RedirectToAction("ErrorForUser", "Home")); } } catch (Exception ex) { TempData["ErrorMessage"] = ex.Message; return(RedirectToAction("ErrorForUser", "Home")); } }