public async Task <IActionResult> Edit(int id, [Bind("Id,CompanyRoleName")] CompanyRole companyRole) { if (id != companyRole.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(companyRole); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyRoleExists(companyRole.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(companyRole)); }
public async Task <CompanyDto> CreateCompany(CompanyToCreateDto companyToCreate) { Address address = new Address { Country = companyToCreate.Address.Country, City = companyToCreate.Address.City, PostalCode = companyToCreate.Address.PostalCode, Street = companyToCreate.Address.Street, HouseNumber = companyToCreate.Address.HouseNumber, BoxNumber = companyToCreate.Address.BoxNumber }; Company company = new Company { Name = companyToCreate.Name, Address = address }; company = await AddAsync(company); CompanyRole defaultRole = new CompanyRole { CompanyId = company.Id, Name = "default", Description = "The default role every new user gets assigned.", IsDefaultRole = true }; await AddAsync(defaultRole); return(ConvertToCompanyDto(company)); }
public async Task <BaseDtoResponse <CompanyRoleDto> > Update(Guid id, CreateCompanyRoleRequest request) { try { CompanyRole role = await _companyRoleRepository.GetById(id); if (role != null) { role.RoleName = request.RoleName; role.Description = request.Description; role.Salary = request.Salary; await _companyRoleRepository.Update(role); CompanyRole updatedResult = await _companyRoleRepository.GetById(id); CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(updatedResult); return(new BaseDtoResponse <CompanyRoleDto>(result)); } else { return(new BaseDtoResponse <CompanyRoleDto>("Role Not found")); } } catch (Exception ex) { return(new BaseDtoResponse <CompanyRoleDto>($"An error occurred when updating the Role: {ex.Message}")); } }
public ActionResult DeleteConfirmed(int id) { CompanyRole companyRole = db.CompanyRoles.Find(id); db.CompanyRoles.Remove(companyRole); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <CompanyRoleDto> GetCompanyRole(int companyRoleId) { CompanyRole companyRole = await _context.CompanyRoles.FirstOrDefaultAsync(x => x.Id == companyRoleId); if (companyRole == null) { return(null); } return(ConvertToCompanyRoleDto(companyRole)); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,CreationDate")] CompanyRole companyRole) { if (ModelState.IsValid) { db.Entry(companyRole).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(companyRole)); }
public ActionResult AddCurriculum(int RoleId, string Curriculum) { CompanyRole cr = db.CompanyRoles.Find(RoleId); Curriculum c = new Curriculum(); c.CurriculumContent = Curriculum; cr.Curriculum.Add(c); db.SaveChanges(); return(RedirectToAction("Details", new { RoleId = RoleId })); }
public async Task CreateCompanyRoleAsync(CompanyRole newCompanyRole) { try { await _context.CompanyRoles.InsertAsync(newCompanyRole); } catch (DataAlreadyExistsException) { AddDataAlreadyExistsProblem(newCompanyRole); } }
public async Task <IActionResult> Create([Bind("Id,CompanyRoleName")] CompanyRole companyRole) { if (ModelState.IsValid) { _context.Add(companyRole); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(companyRole)); }
/// <summary> /// 获取公司类型 /// </summary> /// <param name="o"></param> /// <returns></returns> protected string GetCompanyType(object o) { CompanyRole role = (CompanyRole)o; string companytype = string.Empty; for (int i = 0; i < role.RoleItems.Length; i++) { companytype += role.RoleItems[i].ToString() + "、"; } return(companytype.Remove(companytype.Length - 1)); }
public async Task <bool> DeleteCompanyRole(int companyRoleId) { CompanyRole companyRole = await _context.CompanyRoles.FirstOrDefaultAsync(x => x.Id == companyRoleId); if (companyRole == null) { return(false); } await DeleteAsync(companyRole); return(true); }
public ActionResult Create([Bind(Include = "Id,Name,Description")] CompanyRole companyRole) { if (ModelState.IsValid) { companyRole.CreationDate = DateTime.Now; db.CompanyRoles.Add(companyRole); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(companyRole)); }
public async Task <BaseDtoResponse <CompanyRoleDto> > GetById(Guid id) { CompanyRole role = await _companyRoleRepository.GetById(id); if (role == null) { return(new BaseDtoResponse <CompanyRoleDto>("Role Not Found")); } CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(role); return(new BaseDtoResponse <CompanyRoleDto>(result)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CompanyRole companyRole = db.CompanyRoles.Find(id); if (companyRole == null) { return(HttpNotFound()); } return(View(companyRole)); }
private void AddButton_Click(object sender, EventArgs e) { var DBContext = new SimpleWarehousContext(); CompanyRole tempRole = (CompanyRole)CompanyRoleId.SelectedItem; User temp = new User { Name = NameBox.Text, Surename = SurnameBox.Text, Phone = PhoneBox.Text, Email = EmailBox.Text, AddressId = AdId, CompanyRoleId = tempRole.CompanyRoleId }; MessageBox.Show("Dodawanie klienta " + NameBox.Text); DBContext.Users.Add(temp); DBContext.SaveChanges(); RefreshData(); }
// GET: CompanyRoles/Details/5 public ActionResult Details(int?id) { CompanyRole companyRole = db.CompanyRoles.Find(id); var viewModel = new RolesViewModel(); viewModel.Users = db.Users.ToList(); viewModel.CompanyRole = companyRole; viewModel.ListOfCompanyRoles = db.CompanyRoles.ToList(); viewModel.ListOfEmployeeHasFocuses = db.EmployeeHasFocuses.ToList(); return(View(viewModel)); }
public ActionResult AddToCurrentRoles(int?RoleId) { if (RoleId != null) { string sid = User.Identity.GetUserId(); Employee e = db.Employees.Find(sid); CompanyRole cr = db.CompanyRoles.Find(RoleId); e.CurrentRoles.Add(cr); e.AllRoles.Add(cr); cr.Employees.Add(e); db.SaveChanges(); } return(RedirectToAction("Details", new { RoleId = RoleId })); }
private CompanyRoleDto ConvertToCompanyRoleDto(CompanyRole companyRole) { CompanyRoleDto companyRoleDto = new CompanyRoleDto { Id = companyRole.Id, CompanyId = companyRole.CompanyId, Name = companyRole.Name, Description = companyRole.Description, ManageCompany = companyRole.ManageCompany, ManageUsers = companyRole.ManageUsers, ManageProjects = companyRole.ManageProjects, ManageRoles = companyRole.ManageRoles, }; return(companyRoleDto); }
private void PopulateIdList() { var DBContext = new SimpleWarehousContext(); var roles = DBContext.CompanyRole.ToList(); CompanyRoleId.DataSource = roles; CompanyRoleId.DisplayMember = "RoleName"; CompanyRoleId.ValueMember = "CompanyRoleId"; CompanyRole temp = new CompanyRole(); temp.CompanyRoleId = -1; temp.RoleName = "Brak"; CompanyRoleId.SelectedItem = temp; }
public async Task <CompanyRoleDto> CreateCompanyRole(int companyId, CompanyRoleToCreateDto roleToCreate) { CompanyRole companyRole = new CompanyRole { CompanyId = companyId, Name = roleToCreate.Name, Description = roleToCreate.Description, ManageCompany = roleToCreate.ManageCompany, ManageUsers = roleToCreate.ManageUsers, ManageProjects = roleToCreate.ManageProjects, ManageRoles = roleToCreate.ManageRoles }; companyRole = await AddAsync(companyRole); return(ConvertToCompanyRoleDto(companyRole)); }
public async Task <CompanyRoleDto> UpdateCompanyRole(int companyRoleId, CompanyRoleToUpdateDto roleToUpdate) { CompanyRole companyRole = await _context.CompanyRoles.FirstOrDefaultAsync(x => x.Id == companyRoleId); if (companyRole == null) { return(null); } companyRole.Id = companyRoleId; companyRole.Name = roleToUpdate.Name; companyRole.Description = roleToUpdate.Description; companyRole.ManageCompany = roleToUpdate.ManageCompany; companyRole.ManageUsers = roleToUpdate.ManageUsers; companyRole.ManageProjects = roleToUpdate.ManageProjects; companyRole.ManageRoles = roleToUpdate.ManageRoles; return(ConvertToCompanyRoleDto(await UpdateAsync(companyRole))); }
public ActionResult Create([Bind(Include = "Name,Description")] CompanyRole cr) { if (ModelState.IsValid) { string uid = User.Identity.GetUserId(); Employee e = db.Employees.Find(uid); if (e.CompanyId != null) { int cid = (int)e.CompanyId; cr.CompanyId = cid; db.CompanyRoles.Add(cr); Company c = db.Companies.Find(cid); c.Roles.Add(cr); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View("Error: You must be in a company to add a role (to a company).")); }
public async Task <Company> CreateCompanyAsync(Company company) { var exists = await CompanyRepository.GetFirstWhereAsync(c => c.Name == company.Name); if (exists != null) { throw new AlreadyExistsException("Компания с таким названием уже существует!"); } company.CreatedOn = DateTime.Now; company.Owner = await UserRepository.GetFirstWhereAsync( u => u.UserName == company.Owner.UserName); company.Owner.Company = company; company.CompanyRoles = new List <CompanyRole> { CompanyRole.GetDefaultCompanyAdminRole(), CompanyRole.GetDefaultCompanyOwnerRole() }; var newCompany = await CompanyRepository.CreateAsync(company); await CompanyRepository.SaveAsync(); await UserRepository.UpdateAsync(newCompany.Owner); await UserRepository.SaveAsync(); await UserCompanyRolesRepository.CreateAsync( new UserCompanyRole { CompanyRole = company.CompanyRoles.FirstOrDefault( r => r.Name == CompanyRole.OwnerRoleName), User = company.Owner }); await UserCompanyRolesRepository.SaveAsync(); return(newCompany); }
public async Task <BaseDtoResponse <CompanyRoleDto> > Add(CreateCompanyRoleRequest request) { try { CompanyRole model = _mapper.Map <CreateCompanyRoleRequest, CompanyRole>(request); CompanyRole role = await _companyRoleRepository.Add(model); if (role != null) { CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(role); return(new BaseDtoResponse <CompanyRoleDto>(result)); } else { return(new BaseDtoResponse <CompanyRoleDto>("Unable to create a new role, try again")); } } catch (Exception ex) { return(new BaseDtoResponse <CompanyRoleDto>($"An error occurred when saving the role: {ex.Message}")); } }
public async Task <BaseDtoResponse <CompanyRoleDto> > Delete(Guid id) { try { CompanyRole role = await _companyRoleRepository.GetById(id); if (role != null) { await _companyRoleRepository.Delete(role); CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(role); return(new BaseDtoResponse <CompanyRoleDto>(result)); } else { return(new BaseDtoResponse <CompanyRoleDto>("Unable to delete: Role Not found")); } } catch (Exception ex) { return(new BaseDtoResponse <CompanyRoleDto>($"An error occurred when deleting the role: {ex.Message}")); } }
public void Update(CompanyRole entity) { _companyRoleRepository.Update(entity); }
public async Task <CompanyRoleDto> GetDefaultCompanyRole(int companyId) { CompanyRole defaultRole = await _context.CompanyRoles.Where(x => x.IsDefaultRole == true && x.CompanyId == companyId).FirstOrDefaultAsync(); return(ConvertToCompanyRoleDto(defaultRole)); }
public void Add(CompanyRole entity) { _companyRoleRepository.Add(entity); }
public void Delete(CompanyRole entity) { _companyRoleRepository.Delete(entity); }