public bool AddCompany(ServiceFirstCompanies _objCompany) { bool status = false; try { _objCompany.ServiceFirstCompanyCreatedDate = DateTime.Now; _objCompany.ServiceFirstCompanyIsActive = true; using (ISession session = NHibernateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(_objCompany); transaction.Commit(); } } status = true; } catch (Exception ex) { Message = ex.Message; status = false; } return(status); }
public bool EditCompany(ServiceFirstCompanies _objCompany) { bool status = false; try { using (ISession session = NHibernateSession.OpenSession()) { ServiceFirstCompanies CompanyData; CompanyData = session.Query <ServiceFirstCompanies>().Where(b => b.ServiceFirstCompanyID == _objCompany.ServiceFirstCompanyID).FirstOrDefault(); if (string.IsNullOrEmpty(_objCompany.ServiceFirstCompanyLogoFile)) { _objCompany.ServiceFirstCompanyLogoFile = CompanyData.ServiceFirstCompanyLogoFile; } _objCompany.ServiceFirstCompanyIsActive = CompanyData.ServiceFirstCompanyIsActive; _objCompany.ServiceFirstCompanyCreatedDate = DateTime.Now; session.Clear(); using (ITransaction transaction = session.BeginTransaction()) { session.SaveOrUpdate(_objCompany); transaction.Commit(); } } status = true; } catch (Exception ex) { Message = ex.Message; status = false; } return(status); }
public ActionResult AddCompany(ServiceFirstCompanies _objCompany, 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); _objCompany.ServiceFirstCompanyLogoFile = file.FileName; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } if (_objCompany.ServiceFirstCompanyID == 0) { if (ModelState.IsValid) { _objCompany.ServiceFirstCompanyCreatedDate = DateTime.Now; _objCompany.ServiceFirstCompanyIsActive = true; using (ISession session = NHibernateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(_objCompany); transaction.Commit(); } } ViewBag.Message = "Created Successfully"; } else { ViewBag.Message = "Not Created Successfully"; return(View()); } } else { try { if (ModelState.IsValid) { using (ISession session = NHibernateSession.OpenSession()) { ServiceFirstCompanies CompanyData; CompanyData = session.Query <ServiceFirstCompanies>().Where(b => b.ServiceFirstCompanyID == _objCompany.ServiceFirstCompanyID).FirstOrDefault(); if (string.IsNullOrEmpty(_objCompany.ServiceFirstCompanyLogoFile)) { _objCompany.ServiceFirstCompanyLogoFile = CompanyData.ServiceFirstCompanyLogoFile; } _objCompany.ServiceFirstCompanyIsActive = CompanyData.ServiceFirstCompanyIsActive; _objCompany.ServiceFirstCompanyCreatedDate = DateTime.Now; session.Clear(); using (ITransaction transaction = session.BeginTransaction()) { session.SaveOrUpdate(_objCompany); transaction.Commit(); } } ViewBag.Message = "Saved Successfully"; } else { ViewBag.Message = "Validation data not successfully"; } } catch (Exception ex) { ViewBag.Message = "Error occured:" + ex.Message; } } return(RedirectToAction("AddCompany", "Admin", new { message = ViewBag.Message, id = 0 })); }
public ActionResult AddCompany(ServiceFirstCompanies _objCompany, 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); _objCompany.ServiceFirstCompanyLogoFile = file.FileName; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } if (_objCompany.ServiceFirstCompanyID == 0) { if (ModelState.IsValid) { AdminUsers obj = new AdminUsers(); if (obj.AddCompany(_objCompany)) { ViewBag.Message = "Created Successfully"; } else { ViewBag.Message = obj.Message; } } else { ViewBag.Message = "Not Created Successfully"; return(View()); } } else { try { if (ModelState.IsValid) { AdminUsers obj = new AdminUsers(); if (obj.EditCompany(_objCompany)) { ViewBag.Message = "Saved Successfully"; } else { ViewBag.Message = obj.Message; } } else { ViewBag.Message = "Validation data not successfully"; } } catch (Exception ex) { ViewBag.Message = "Error occured:" + ex.Message; } } return(RedirectToAction("AddCompany", "Admin", new { message = ViewBag.Message, id = 0 })); }