Example #1
0
        public ActionResult Add(Company company)
        {
            try
            {
                string startTrial = Request.Form["startTrial"];
                string buyNow = Request.Form["buyNow"];
                company.Email = HttpContext.User.Identity.Name;
                var tt = uService.GetSingleUserByEmail(company.Email);
                company.Users = new User { Id = tt.Id, Email = tt.Email };
                string msg="";
                var chkTrading = iCompany.IsTradingNameUnique(company, out msg);

                if (!chkTrading)
                {
                    TempData.Add("errMsg",msg);
                    return RedirectToAction("Add");
                }
                if (iCompany.AddCompany(company))
                {
                    // company view log
                    var cViewlog = new CompanyViewLog();
                    cViewlog.CompanyId = company.Id;
                    cViewlog.UserId = tt.Id;
                    cViewlog.LoginTime = DateTime.Now;
                    _companyViewLog.AddCompanyViewLog(cViewlog);

                    // insert default data for company
                    var rr = iCompany.InsertDefaultDataForCompany(company.Id);

                    if (startTrial != null)
                    {
                        return RedirectToAction("Update", "Company", new { Area = "OrganizationManagement" });
                    }
                    else
                    {
                        return RedirectToAction("payment", "Company", new { Area = "OrganizationManagement" });
                    }

                }
                else
                {
                    return RedirectToAction("Add", "Company", new { Area = "OrganizationManagement" });
                }

            }
            catch (Exception Ex)
            {
                return RedirectToAction("Add", "Company", new { Area = "OrganizationManagement" });
            }
        }
Example #2
0
        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");
        }
Example #3
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();
        }