Exemplo n.º 1
0
        public ActionResult EditCompany(CompanyCreateEditModel model)
        {
            if (ModelState.IsValid)
            {
                ContextManager.SaveCompany(model);
                return(RedirectToAction("Details", new { id = model.Id }));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult CreateCompany(CompanyCreateEditModel model)
        {
            if (ModelState.IsValid)
            {
                ContextManager.SaveCompany(model);
                return(RedirectToAction("List"));
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult EditCompany(int id)
        {
            var cookie      = Request.Cookies["session-" + id];
            var companyUser = ContextManager.GetCompanyUser(id);

            if (cookie == null && companyUser != null)
            {
                return(RedirectToAction("Login", "Login", new { companyId = id }));
            }
            else if (cookie != null && companyUser != null)
            {
                var sessionId = Guid.Parse(cookie.Value);
                var userAudit = ContextManager.GetUserBySession(sessionId);

                if (!ContextManager.Authorize(userAudit))
                {
                    return(RedirectToAction("Login", "Login", new { companyId = id }));
                }
            }

            var model   = new CompanyCreateEditModel();
            var company = ContextManager.GetCompanyById(id);

            model.Id          = company.Id;
            model.Name        = company.Name;
            model.Budget      = company.Budget;
            model.AddressLine = company.AddressLine;
            model.CompanyId   = company.CompanyId;
            model.OwnerId     = company.OwnerId;

            if (companyUser != null)
            {
                model.Login    = companyUser.Login;
                model.Password = companyUser.Password;
            }


            return(View(model));
        }
Exemplo n.º 4
0
        public static void SaveCompany(CompanyCreateEditModel model)
        {
            using (var session = Store.OpenSession())
            {
                var company = new Company
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    Budget      = model.Budget,
                    AddressLine = model.AddressLine,
                    CompanyId   = model.CompanyId,
                    OwnerId     = model.OwnerId,
                };

                session.Store(company);

                if (model.Login != null && model.Password != null)
                {
                    var newCompanyId = company.Id;

                    var userAudit = new UserAudit
                    {
                        CompanyId         = newCompanyId,
                        Login             = model.Login,
                        Password          = model.Password,
                        LastAuthorization = DateTime.Now
                    };

                    session.Store(userAudit);

                    company.OwnerId = userAudit.Id;

                    session.Store(company);
                }
                session.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public ActionResult CreateCompany()
        {
            var model = new CompanyCreateEditModel();

            return(View(model));
        }