예제 #1
0
        public ActionResult AddCompanyManager(ServiceFirstCompanyManager _objCompanyManager, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = System.IO.Path.Combine(Server.MapPath("~/Images"),
                                                         System.IO.Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    _objCompanyManager.ServiceFirstCompanyManagerLogoFile = file.FileName;
                }
                catch (Exception ex)
                {
                    TempData["message"] = "ERROR:" + ex.Message.ToString();
                }
            }
            if (_objCompanyManager.ServiceFirstCompanyManagerID == 0)
            {
                if (ModelState.IsValid)
                {
                    Users obj = new Users();
                    if (obj.AddCompanyManager(_objCompanyManager))
                    {
                        ViewBag.Message = "Created Successfully";
                    }
                    else
                    {
                        ViewBag.Message = obj.Message;
                    }
                }
                else
                {
                    ViewBag.Message = "Not Created Successfully";
                }
            }
            else
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        using (ISession session = NHibernateSession.OpenSession())
                        {
                            ServiceFirstCompanies CompanyData;
                            CompanyData = session.Query <ServiceFirstCompanies>().Where(b => b.ServiceFirstCompanyID
                                                                                        == _objCompanyManager.ServiceFirstCompanyManagerID).FirstOrDefault();
                            if (string.IsNullOrEmpty(_objCompanyManager.ServiceFirstCompanyManagerLogoFile))
                            {
                                _objCompanyManager.ServiceFirstCompanyManagerLogoFile = CompanyData.ServiceFirstCompanyLogoFile;
                            }
                            _objCompanyManager.ServiceFirstCompanyManagerIsActive    = CompanyData.ServiceFirstCompanyIsActive;
                            _objCompanyManager.ServiceFirstCompanyManagerCreatedDate = DateTime.Now;
                            string _salt     = string.Empty;
                            string _password = string.Empty;
                            CommonFunctions.GeneratePassword(_objCompanyManager.ServiceFirstCompanyManagerPassword,
                                                             "new", ref _salt, ref _password);

                            _objCompanyManager.ServiceFirstCompanyManagerPassword     = _password;
                            _objCompanyManager.ServiceFirstCompanyManagerPasswordSalt = _salt;
                            session.Clear();
                            using (ITransaction transaction = session.BeginTransaction())
                            {
                                session.SaveOrUpdate(_objCompanyManager);
                                transaction.Commit();
                            }
                            CommonFunctions.SendMail(_objCompanyManager);
                        }
                        ViewBag.Message = "Saved Successfully";
                    }
                    else
                    {
                        ViewBag.Message = "Validation data not successfully";
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Error occured:" + ex.Message;
                }
            }
            return(RedirectToAction("AddCompanyManager", "Admin", new { message = ViewBag.Message, id = 0 }));
        }