public bool AddCompanyDocument(CompanyDocument cd) { try { cd.State = ObjectState.Added; companyRep.AddOperation(cd); return true; } catch (Exception ex) { var rr = ex.Message; return false; } }
public ActionResult Update(Company company) { string msg = "", logoUploadMsg = "", sealUploadMsg = "", documentAddMsg = ""; bool success = false, uploadSuccess = true; HttpPostedFileBase logo = Request.Files["logoImage"]; HttpPostedFileBase seal = Request.Files["sealImage"]; //HttpPostedFileBase doc = Request.Files["documentLocation[]"]; if (logo.ContentLength > 0) { string logoName, logoLocation; if (company.LogoLocation == null) { logoName = "Logo_" + company.TradingName.Replace(" ", "_") + "_" + company.Id.ToString() + "_" + Path.GetRandomFileName() + ".png"; logoLocation = Server.MapPath("~/Uploads/" + company.TradingName.Replace(" ", "_") + "/"); } else { logoName = company.LogoLocation.Split('/').Last(); logoLocation = company.LogoLocation; logoLocation = Path.GetDirectoryName(logoLocation);// logoLocation.TrimEnd('\\'); //logoLocation = logoLocation.Remove(logoLocation.LastIndexOf('\\') + 1); logoLocation = Server.MapPath("~/" + logoLocation + "/"); } string tempPath = Server.MapPath("~/Uploads/Temp"); if (System.IO.File.Exists(logoLocation + logoName)) { if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } System.IO.File.Move(logoLocation + logoName, tempPath + logoName); } if (fileUpload(logo, logoName, logoLocation)) { if (System.IO.File.Exists(tempPath + logoName)) { System.IO.File.Delete(tempPath + logoName); } company.LogoLocation = "Uploads/" + company.TradingName.Replace(" ", "_") + "/" + logoName; } else { if (System.IO.File.Exists(tempPath + logoName)) System.IO.File.Move(tempPath + logoName, logoLocation + logoName); logoUploadMsg = "Problem in logo uploading...Please try Again later.."; uploadSuccess = false; } } if (seal.ContentLength > 0) { string sealName, sealLocation; if (company.SealLocation == null) { sealName = "Seal_" + company.TradingName.Replace(" ", "_") + "_" + company.Id.ToString() + "_" + Path.GetRandomFileName() + ".png"; sealLocation = Server.MapPath("~/Uploads/" + company.TradingName.Replace(" ", "_") + "/"); } else { sealName = company.SealLocation.Split('/').Last(); sealLocation = company.SealLocation; sealLocation = Path.GetDirectoryName(sealLocation); ; sealLocation = Server.MapPath("~/" + sealLocation + "/"); } string tempPath = Server.MapPath("~/Uploads/Temp"); if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } if (System.IO.File.Exists(sealLocation + sealName)) { System.IO.File.Move(sealLocation + sealName, tempPath + sealName); } if (fileUpload(seal, sealName, sealLocation)) { if (System.IO.File.Exists(tempPath + sealName)) { System.IO.File.Delete(tempPath + sealName); } company.SealLocation = "Uploads/" + company.TradingName.Replace(" ", "_") + "/" + sealName; } else { if (System.IO.File.Exists(tempPath + sealName)) System.IO.File.Move(tempPath + sealName, sealLocation + sealName); sealUploadMsg = "Problem in Seal uploading...Please try Again later.."; uploadSuccess = false; } } string documentName; string documentLocation; try { if(company.CompleteFlag==0) company.CompleteFlag = 1; if (iCompany.UpdateCompany(company)) { msg = "Success"; success = true; for (int i = 0; i < Request.Files.Count; i++) { if ("documentLocation[]" == Request.Files.GetKey(i) && Request.Files.GetKey(i).Length > 1) { documentName = "Document_" + company.TradingName.Replace(" ", "_") + "_" + Path.GetRandomFileName() + Path.GetExtension(Request.Files[i].FileName); documentLocation = Server.MapPath("~/Uploads/" + company.TradingName.Replace(" ", "_") + "/"); if (fileUpload(Request.Files[i], documentName, documentLocation)) { CompanyDocument cd = new CompanyDocument(); cd.CompanyId = company.Id; cd.DocumentOriginalName = Request.Files[i].FileName; cd.DocumentLocation = "Uploads/" + company.TradingName.Replace(" ", "_") + "/" + documentName; if (!iCompanyDocument.AddCompanyDocument(cd)) { documentAddMsg = "One or more document did not upload successfully"; uploadSuccess = false; } } } } if (company.CompleteFlag == 1) return RedirectToAction("Create", "FinalcialSetting", new { Area = "OrgSettings" }); else return RedirectToAction("update"); } else msg = "Update Failed"; } catch (Exception) { msg = "Failed"; } TempData.Add("errMsg", msg + logoUploadMsg + sealUploadMsg + documentAddMsg); if (success && uploadSuccess) return RedirectToAction("MyMhasb", "Users", new { Area = "UserManagement" }); else if (!uploadSuccess) return RedirectToAction("update"); else return RedirectToAction("update"); }
public ActionResult Registration(Company company) { HttpPostedFileBase logo = Request.Files["logoImage"]; HttpPostedFileBase seal = Request.Files["sealImage"]; //HttpPostedFileBase doc = Request.Files["documentLocation[]"]; int companyTableId = iCompany.GetMaxId() + 1; string sealName = "Seal_" + company.TradingName.Replace(" ", "_") + "_" + companyTableId.ToString() + "_" + Path.GetRandomFileName() + ".png"; string sealLocation = Server.MapPath("~/Uploads/" + company.TradingName.Replace(" ", "_") + "/"); string logoName = "Logo_" + company.TradingName.Replace(" ", "_") + "_" + companyTableId.ToString() + "_" + Path.GetRandomFileName() + ".png"; string logoLocation = Server.MapPath("~/Uploads/" + company.TradingName.Replace(" ", "_") + "/"); string msg = "", logoUploadMsg = "", sealUploadMsg = "", designationInsertMsg = "", employeeAddMsg = "", documentAddMsg = "", settingMsg = ""; bool success = false, uploadSuccess = true; string documentName; string documentLocation; if (logo.ContentLength > 1) { if (fileUpload(logo, logoName, logoLocation)) { company.LogoLocation = "Uploads/" + company.TradingName.Replace(" ", "_") + "/" + logoName; } else { logoUploadMsg = "Problem in logo uploading...Please try Again later.."; uploadSuccess = false; } } if (seal.ContentLength > 1) { if (fileUpload(seal, sealName, sealLocation)) { company.SealLocation = "Uploads/" + company.TradingName.Replace(" ", "_") + "/" + sealName; } else { sealUploadMsg = "Problem in Seal uploading...Please try Again later.."; uploadSuccess = false; } } company.Email = HttpContext.User.Identity.Name; var tt = uService.GetSingleUserByEmail(company.Email); company.Users = new User { Id = tt.Id, Email = tt.Email }; try { if (iCompany.AddCompany(company)) { success = true; var ownerDesignation = iDesignation.GetSingleDesignationByDesignationName("Owner"); if (ownerDesignation == null) { Designation ds = new Designation(); ds.DesignationName = "Owner"; if (iDesignation.AddDesignation(ds)) ownerDesignation = ds; else { //designation add failed designationInsertMsg = "Internal Server Error regarding Designation...Please consult with Mhasb Team"; } } Employee ownerEmp = new Employee(); ownerEmp.UserId = tt.Id; ownerEmp.CompanyId = company.Id; ownerEmp.DesignationId = ownerDesignation.Id; ownerEmp.BranchId = company.Id; if (!iEmployee.CreateEmployee(ownerEmp)) { //Employee add failed designationInsertMsg = "Internal Server Error regarding Employee...Please consult with Mhasb Team"; } var accountSetting = sService.GetAllByUserId(tt.Id); if (accountSetting != null) { accountSetting.Companies = new Company { Id = company.Id }; accountSetting.lgcompany = true; if (!sService.UpdateSettings(accountSetting)) settingMsg = "Internal Server Error regarding Account Setting...Please consult with Mhasb Team "; } else { var AccSet = new Settings(); AccSet.userId = tt.Id; AccSet.lgdash = false; AccSet.lglast = false; AccSet.CompanyId = company.Id; AccSet.lgcompany = true; if (!sService.AddSettings(AccSet)) settingMsg = "Internal Server Error regarding Account Setting...Please consult with Mhasb Team"; } for (int i = 0; i < Request.Files.Count; i++) { if ("documentLocation[]" == Request.Files.GetKey(i) && Request.Files.GetKey(i).Length > 1) { documentName = "Document_" + company.TradingName.Replace(" ", "_") + "_" + companyTableId.ToString() + "_" + Path.GetRandomFileName() + Path.GetExtension(Request.Files[i].FileName); documentLocation = Server.MapPath("~/Uploads/" + company.TradingName.Replace(" ", "_") + "/"); if (fileUpload(Request.Files[i], documentName, documentLocation)) { CompanyDocument cd = new CompanyDocument(); cd.CompanyId = company.Id; cd.DocumentOriginalName = Request.Files[i].FileName; cd.DocumentLocation = "Uploads/" + company.TradingName.Replace(" ", "_") + "/" + documentName; if (!iCompanyDocument.AddCompanyDocument(cd)) { documentAddMsg = "One or more document didnot upload successfully"; uploadSuccess = false; } } } } msg = "Success"; } else msg = "Registration Failed"; } catch (Exception) { msg = "Exception Occured. Please Contact with Mhasb Team"; } TempData.Add("errMsg", msg + logoUploadMsg + sealUploadMsg + documentAddMsg + designationInsertMsg + employeeAddMsg + settingMsg); if (success && uploadSuccess) return RedirectToAction("MyMhasb", "Users", new { Area = "UserManagement" }); else if (!uploadSuccess) return RedirectToAction("update"); else return View(); }