Exemplo n.º 1
0
        public ActionResult Edit(int code, Company collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    companiesRepository.updateCompany(collection);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(collection));
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit([Bind(Include = "Company_Id,Company_Name,IsActive,Company_Contacts,Company_Admin,CompanyColor")] Company company)
        {
            if (company.Company_Name != "" && company.CompanyColor != "")
            {
                var Color_exist = cmpRepo.getAllCompanies().Where(x => x.CompanyColor == company.CompanyColor).FirstOrDefault();
                if (Color_exist != null && Color_exist.Company_Id != company.Company_Id)
                {
                    ModelState.AddModelError(string.Empty, "There is something wrong with Foo.");
                    return(View(company));
                }

                if (company.Company_Admin != "")
                {
                    UserRole users = new UserRole();
                    users.EmailId = company.Company_Admin;
                    users.IsAdmin = true;
                    SaveAdminAndContacts(users);

                    UserAccess Role = new UserAccess()
                    {
                        CompanyId  = company.Company_Id,
                        UserRoleId = cmpRepo.getAllUserrole().Where(x => x.EmailId == company.Company_Contacts).Select(x => x.UserRoleId).FirstOrDefault()
                    };
                    UpdateUserAccess(Role);
                }

                if (company.Company_Contacts != "")
                {
                    UserRole users = new UserRole();
                    users.EmailId = company.Company_Admin;
                    users.IsAdmin = false;
                    SaveAdminAndContacts(users);


                    UserAccess Role = new UserAccess()
                    {
                        CompanyId  = company.Company_Id,
                        UserRoleId = cmpRepo.getAllUserrole().Where(x => x.EmailId == company.Company_Contacts).Select(x => x.UserRoleId).FirstOrDefault()
                    };
                    UpdateUserAccess(Role);
                }
                cmpRepo.updateCompany(company);
                return(RedirectToAction("Index"));
            }
            return(View(company));
        }
 /**
  * PUT request that updates a company
  */
 public Response Put(int id, company cop)
 {
     return(repository.updateCompany(id, cop));
 }