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 DeleteGlnTagType(int id)
        {
            GlnTagType glnTagType = _unitOfWork.GlnTagType.FindSingle(tt => tt.GlnTagTypeId == id);

            if (glnTagType == null)
            {
                return(NotFound());
            }

            _unitOfWork.GlnTagType.Remove(glnTagType);
            _unitOfWork.Complete();
            _logger.SuccessfulServerLog("Tag Type deleted", HttpContext.Current.User, DtoHelper.CreateGlnTagTypeDto(glnTagType), new object());

            return(Ok(DtoHelper.CreateGlnTagTypeDto(glnTagType)));
        }
Exemplo n.º 3
0
        public static GlnTagTypeDto CreateGlnTagTypeDto(GlnTagType glnTagType)
        {
            var tagTypeDto = new GlnTagTypeDto()
            {
                GlnTagTypeId = glnTagType.GlnTagTypeId,
                Code         = glnTagType.Code,
                Description  = glnTagType.Description,
                Active       = glnTagType.Active
            };

            //tagTypeDto.GlnTags = glnTagType.GlnTags?.Select(t => new GlnTagDto()
            //{
            //    Active = t.Active,
            //    GlnId = t.GlnId,
            //    GlnTagTypeId = t.GlnTagTypeId,
            //    GlnTagId = t.GlnTagId,
            //    TypeKey = t.TypeKey
            //}).ToList();

            return(tagTypeDto);
        }