Example #1
0
 public ActionResult Edit(Designation ds)
 {
     if (iDesignation.UpdateDesignation(ds))
         return RedirectToAction("Index", "Designation", new { Area = "OrganizationManagement" });
     else
     {
         ModelState.AddModelError("msg", "Designation did not Updated successfully");
         return View();
     }
 }
Example #2
0
        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();
        }