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 PostGlnTagType(GlnTagTypeDto glnTagTypeDto) { if (!ModelState.IsValid) { _logger.FailedToCreateServerLog(HttpContext.Current.User, "Unable to create new tag type, state invalid.", "", glnTagTypeDto); return(BadRequest(ModelState)); } var sameDescription = _unitOfWork.GlnTagType.Find(tt => tt.Description == glnTagTypeDto.Description); var sameCode = _unitOfWork.GlnTagType.Find(tt => tt.Code == glnTagTypeDto.Code); if (sameDescription.Any()) { _logger.FailedToCreateServerLog(HttpContext.Current.User, $"A GlnTagType already exists with this decription: {glnTagTypeDto.Description}", "", glnTagTypeDto); return(BadRequest($"A GlnTagType already exists with this decription: {glnTagTypeDto.Description}")); } if (sameCode.Any()) { _logger.FailedToCreateServerLog(HttpContext.Current.User, $"A GlnTagType already exists with this code: {glnTagTypeDto.Code}", "", glnTagTypeDto); return(BadRequest($"A GlnTagType already exists with this code: {glnTagTypeDto.Code}")); } var glnTagType = new GlnTagType() { Active = glnTagTypeDto.Active, Code = glnTagTypeDto.Code, CreatedDateTime = DateTime.Now, Description = glnTagTypeDto.Description, ModifiedDateTime = DateTime.Now, UserCreated = HttpContext.Current.User.ToString() }; _unitOfWork.GlnTagType.Add(glnTagType); try { _unitOfWork.Complete(); _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateGlnTagTypeDto(glnTagType)); } catch (Exception e) { Console.WriteLine(e); _logger.FailedToCreateServerLog(HttpContext.Current.User, e.Message, e.InnerException, glnTagTypeDto); return(InternalServerError()); } return(Ok(DtoHelper.CreateGlnTagTypeDto(glnTagType))); }
public IHttpActionResult PostGlnTag(GlnTagDto glnTagDto) { if (!ModelState.IsValid) { _logger.FailedToCreateServerLog(HttpContext.Current.User, "Unable to create new tag, state invalid.", "", glnTagDto); return(BadRequest(ModelState)); } if (TagAlreadyExistOnGln(glnTagDto)) { _logger.FailedToCreateServerLog(HttpContext.Current.User, $"GLN already has this tag associated with it.", "", glnTagDto); return(BadRequest($"GLN already has this tag associated with it.")); } var glnTag = new GlnTag() { Active = true, CreatedDateTime = DateTime.Now, GlnId = glnTagDto.GlnId, GlnTagTypeId = glnTagDto.GlnTagTypeId, TypeKey = glnTagDto.TypeKey, UserCreated = HttpContext.Current.User.ToString() }; _unitOfWork.GlnTag.Add(glnTag); try { _unitOfWork.Complete(); _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateGlnTagDto(glnTag)); } catch (Exception e) { Console.WriteLine(e); _logger.FailedToCreateServerLog(HttpContext.Current.User, e.Message, e.InnerException, glnTagDto); return(InternalServerError()); } return(Ok(glnTagDto)); }