public IHttpActionResult AddAddress(Address newAddress) { if (Equals(newAddress, null)) { return(BadRequest()); } try { newAddress.Version = 1; newAddress.Country = "GBR"; newAddress.Active = true; _unitOfWork.Addresses.Add(newAddress); _unitOfWork.Complete(); _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateAddressDto(newAddress)); return(Ok(newAddress)); } catch (Exception ex) { _logger.FailedToCreateServerLog <Exception, object>(HttpContext.Current.User, ex.Message, ex.InnerException); return(InternalServerError()); } }
public IHttpActionResult AddNewAdditionalContact([FromBody] AdditionalContact newAdditionalContact) { if (Equals(newAdditionalContact, null)) { return(BadRequest()); } var additionalContact = _unitOfWork.AdditionalContacts.Find(ac => ac.Email == newAdditionalContact.Email); if (additionalContact.Any()) { return(Content(HttpStatusCode.Conflict, "Contact with same email already exists.")); } try { _unitOfWork.AdditionalContacts.Add(newAdditionalContact); _unitOfWork.Complete(); _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(newAdditionalContact)); return(Ok(DtoHelper.CreateAdditionalContactDto(newAdditionalContact))); } catch (Exception ex) { _logger.FailedToCreateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAdditionalContactDto(newAdditionalContact)); return(InternalServerError(ex)); } }
public IHttpActionResult PutGlnTag(GlnTag glnTag) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var tagToBeUpdated = _unitOfWork.GlnTag.FindSingle(t => t.GlnTagId == glnTag.GlnTagId); if (Equals(tagToBeUpdated, null)) { return(NotFound()); } var beforeUpdate = DtoHelper.CreateGlnTagDto(tagToBeUpdated); if (TagAlreadyExistOnGln(DtoHelper.CreateGlnTagDto(glnTag))) { _logger.FailedToCreateServerLog(HttpContext.Current.User, $"GLN already has this tag associated with it.", "", DtoHelper.CreateGlnTagDto(glnTag)); return(BadRequest($"GLN already has this tag associated with it.")); } tagToBeUpdated.Active = glnTag.Active; tagToBeUpdated.GlnId = glnTag.GlnId; tagToBeUpdated.GlnTagTypeId = glnTag.GlnTagTypeId; tagToBeUpdated.TypeKey = glnTag.TypeKey; tagToBeUpdated.ModifiedDateTime = DateTime.Now; tagToBeUpdated.UserModified = HttpContext.Current.User.ToString(); _unitOfWork.GlnTag.Update(tagToBeUpdated); try { _unitOfWork.Complete(); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, beforeUpdate, DtoHelper.CreateGlnTagDto(tagToBeUpdated)); } catch (DbUpdateConcurrencyException) { _logger.FailedToCreateServerLog(HttpContext.Current.User, "Unable to create new tag type", "", DtoHelper.CreateGlnTagDto(tagToBeUpdated)); return(InternalServerError()); } return(Ok(DtoHelper.CreateGlnTagDto(tagToBeUpdated))); }
public IHttpActionResult PutGlnTagType(GlnTagTypeDto glnTagType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var tagTypeToBeUpdated = _unitOfWork.GlnTagType.FindSingle(tt => tt.GlnTagTypeId == glnTagType.GlnTagTypeId); if (Equals(tagTypeToBeUpdated, null)) { return(NotFound()); } var beforeUpdate = DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated); tagTypeToBeUpdated.Code = glnTagType.Code; tagTypeToBeUpdated.Description = glnTagType.Description; tagTypeToBeUpdated.ModifiedDateTime = DateTime.Now; tagTypeToBeUpdated.UserModified = HttpContext.Current.User.ToString(); tagTypeToBeUpdated.Active = glnTagType.Active; _unitOfWork.GlnTagType.Update(tagTypeToBeUpdated); try { _unitOfWork.Complete(); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, beforeUpdate, DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated)); } catch (DbUpdateConcurrencyException) { _logger.FailedToCreateServerLog(HttpContext.Current.User, "Unable to create new tag type", "", DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated)); return(InternalServerError()); } return(Ok(DtoHelper.CreateGlnTagTypeDto(tagTypeToBeUpdated))); //return StatusCode(HttpStatusCode.NoContent); }