Ejemplo n.º 1
0
        private bool TagAlreadyExistOnGln(GlnTagDto glnTagDto)
        {
            var alreadyOnGln =
                _unitOfWork.GlnTag.Find(t => t.GlnId == glnTagDto.GlnId && t.GlnTagTypeId == glnTagDto.GlnTagTypeId);

            if (alreadyOnGln.Any())
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }