Ejemplo n.º 1
0
        public async Task <IResult> UpdateTemplate(ContentViewModel contentView)
        {
            var result = new Result
            {
                Operation = Operation.Update,
                Status    = Status.Success
            };

            try
            {
                var template = _templateRepository.GetTemplate(contentView.Id);
                if (template == null)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "Template does not exist.";
                    return(result);
                }
                ContentModel content = new ContentModel();
                content.MapFromViewModel(contentView);
                if ((template.TemplateName == content.TemplateName) && (template.Id != content.Id))
                {
                    var nameCheck = _templateRepository.ExistingName(content.TemplateName);
                    if (nameCheck)
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "sameNameMessage";
                        return(result);
                    }
                }
                if ((template.Content == content.Content) && (template.Id != content.Id))
                {
                    var contentCheck = _templateRepository.ExistingContent(content);
                    if (contentCheck)
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "sameContentMessage";
                        return(result);
                    }
                }
                var updateTemplate = await _templateRepository.UpdateTemplate(content);

                return(updateTemplate);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }