public IHttpActionResult GetGlnTag(int id) { GlnTag glnTag = _unitOfWork.GlnTag.FindSingle(tt => tt.GlnTagId == id); if (glnTag == null) { return(NotFound()); } return(Ok(DtoHelper.CreateGlnTagDto(glnTag))); }
public IHttpActionResult DeleteGlnTag(int id) { GlnTag glnTag = _unitOfWork.GlnTag.FindSingle(tt => tt.GlnTagId == id); if (glnTag == null) { return(NotFound()); } _unitOfWork.GlnTag.Remove(glnTag); _unitOfWork.Complete(); _logger.SuccessfulServerLog("Tag Type deleted", HttpContext.Current.User, DtoHelper.CreateGlnTagDto(glnTag), new object()); return(Ok(DtoHelper.CreateGlnTagDto(glnTag))); }
public static GlnTagDto CreateGlnTagDto(GlnTag glnTag) { var glnTagDto = new GlnTagDto() { Active = glnTag.Active, GlnId = glnTag.GlnId, GlnTagId = glnTag.GlnTagId, GlnTagTypeId = glnTag.GlnTagTypeId, TypeKey = glnTag.TypeKey }; if (!Equals(glnTag.GlnTagType, null)) { glnTagDto.GlnTagType = CreateGlnTagTypeDto(glnTag.GlnTagType); } return(glnTagDto); }
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 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)); }