public CompanyDTO SaveCompany(CompanyDTO company) { if (company == null) { return(null); } if (string.IsNullOrWhiteSpace(company.FullName)) { throw new ArgumentException("Full name is missing."); } if (string.IsNullOrWhiteSpace(company.ShortName)) { throw new ArgumentException("Short name is missing"); } Company savedCompany = null; if (company.Id.HasValue) { savedCompany = companiesRepository.Update(Company.Hydrate(company)); } else { savedCompany = companiesRepository.Insert(Company.Hydrate(company)); } if (savedCompany != null) { return(savedCompany.getDTO()); } else { return(null); } }
public async Task <Response <CompanyDTO> > Update(Guid companyId, Guid userId, CompanyUpdateDTO dto) { var companyUser = await _companiesUsersRepository.GetCompanyUser(companyId, userId); if (companyUser == null) { return(new BusinessConflictErrorResponse <CompanyDTO>(new [] { new Error { Code = ErrorCodes.Common.NotFound, Message = ErrorMessages.Common.NotFound, Field = "userId" } })); } if (companyUser.Status != MembershipStatus.SuperAdmin) { return(new ForbiddenErrorResponse <CompanyDTO>(new [] { new Error { Code = ErrorCodes.Security.Forbidden, Message = ErrorMessages.Security.Forbidden } })); } var companyEntity = await _repository.GetById(companyId); if (companyEntity == null) { return(new BusinessConflictErrorResponse <CompanyDTO>(new [] { new Error { Code = ErrorCodes.Common.NotFound, Message = ErrorMessages.Common.NotFound, Field = "companyId" } })); } companyEntity.Name = dto.Name; companyEntity.Address = dto.Address; companyEntity = await _repository.Update(companyEntity); var result = _mapper.Map <CompanyModel, CompanyDTO>(companyEntity); return(new Response <CompanyDTO> { Data = result }); }
public async Task <Company> UpdateCompany(Company company) { _companiesRepository.Update(company); if (await _companiesRepository.SaveChangesAsync()) { return(company); } else { return(null); } }
public IActionResult Put(int id, [FromBody] Company company) { var companyDetails = _companiesRepository.Get(id); if (companyDetails == null) { return(NotFound()); } var dbCompany = Mapper.Map <DbCompany>(company); _companiesRepository.Update(dbCompany); _companiesRepository.SaveChanges(); return(NoContent()); }
public async Task <Response> SetCompanyStatus(Guid companyId, CompanyStatus status) { var companyEntity = await _companiesRepository.GetById(companyId); if (companyEntity == null) { return(new NotFoundErrorResponse()); } if (companyEntity.Status == status) { return(new Response()); } companyEntity.Status = status; await _companiesRepository.Update(companyEntity); return(new Response()); }
public async Task <IActionResult> Update(long id, CompanyDTO companyDTO) { try { // get company by id Company company = await _companiesRepository.GetById(id); // change data with with dto company.UpdateByDTO(companyDTO); // update model await _companiesRepository.Update(company); return(Ok()); } catch (InvalidOperationException) { return(NotFound("None existing company")); } }
public async Task <JsonResult> SyncCompanies() { var knownCompanies = await _companiesRepository.GetAllCompanies(); var radarioCompanies = mf.CompanyManager.GetAllCompanies(); var updateCount = 0; var insertCount = 0; foreach (var radarioCompany in radarioCompanies) { var entity = knownCompanies.SingleOrDefault(x => x.CompanyId == radarioCompany.Id); if (entity == null) { entity = new Company() { CompanyId = radarioCompany.Id, CompanyTitle = radarioCompany.Title, PublicGuid = Guid.NewGuid(), FullAccessGuid = Guid.NewGuid() }; await _companiesRepository.Insert(entity); insertCount++; } else { if (!radarioCompany.Title.Equals(entity.CompanyTitle, StringComparison.InvariantCultureIgnoreCase)) { entity.CompanyTitle = radarioCompany.Title; await _companiesRepository.Update(entity); updateCount++; } } } return(Json(new { Updated = updateCount, CreatedNew = insertCount }, JsonSerializerSettings)); }
public async Task UploadPicture(IFormFile picture) { var user = await userRepository.GetByName(UserInfo.UserName); var company = companiesRepository.GetBydId(user.Id); if (picture != null && picture.Length > 0) { byte[] pictureBytes = null; using (var fileStream = picture.OpenReadStream()) { using (var memoryStram = new MemoryStream()) { fileStream.CopyTo(memoryStram); pictureBytes = memoryStram.ToArray(); } } company.Picture = pictureBytes; companiesRepository.Update(company); companiesRepository.Save(); } }
public bool Update(CompanyModel model) { return(_repository.Update(model)); }
public void Update(Company company) { _repository.Update(company); _unitOfWork.Commit(); }
public IHttpActionResult Put(Company comp) { _repository.Update(comp); _repository.Save(); return(StatusCode(HttpStatusCode.NoContent)); }