public async Task UpdateAsync(UpdateTextModel updateModel)
        {
            if (updateModel == null || updateModel.IsEmpty())
            {
                throw new ExceptionTypes.NullValueException();
            }
            if (updateModel.Id < 1)
            {
                throw new ExceptionTypes.IncorrectIdException();
            }

            if (!await _repository.ExistAsync(updateModel.Id))
            {
                throw new ExceptionTypes.TextNotExistException();
            }

            if (updateModel.MailingId.HasValue && !await _repositoryMailing.ExistAsync(updateModel.MailingId.Value))
            {
                throw new ExceptionTypes.MailingNotExistException();
            }
            else if (updateModel.MailingId.HasValue)
            {
                updateModel.Mail = await _repositoryMailing.GetCourseAsync(updateModel.MailingId.Value);
            }

            await _repository.UpdateAsync(updateModel);
        }
        public async Task UpdateAsync_ThrowsExpected(UpdateTextModel updateModel,
                                                     Type type, string message)
        {
            //arrange

            //act
            var exception = Assert.ThrowsAsync(type, () => _service.UpdateAsync(updateModel));

            // assert
            Assert.AreEqual(message, exception.Message);
            Assert.AreEqual(exception.GetType(), type);
        }
        public async Task UpdateAsync(UpdateTextModel updateModel)
        {
            var text = await _dbContext.Texts.FirstOrDefaultAsync(t => t.TextId == updateModel.Id);

            if (updateModel.InfomationPart != null)
            {
                text.InfomationPart = updateModel.InfomationPart;
            }

            if (updateModel.Mail != null)
            {
                text.Mail = updateModel.Mail;
            }

            _dbContext.Update(text);
            await _dbContext.SaveChangesAsync();
        }
Exemple #4
0
        public async Task <IActionResult> UpdateTextAsync(UpdateTextModel updateModel)
        {
            try
            {
                await _service.UpdateAsync(updateModel);

                return(Ok("Обновлено."));
            }
            catch (ExceptionTypes.NotExistException er)
            {
                return(NotFound(er.StackTrace));
            }
            catch (Exception er)
            {
                return(BadRequest(er.StackTrace));
            }
        }
        public IActionResult UpdateText(UpdateTextModel model)
        {
            bool v = TryValidateModel(model);

            if (v == false)
            {
                return(this.NotFound());
            }
            var txt = mContext.Texts.FirstOrDefault(a => a.Id == model.Id);

            if (txt == null)
            {
                return(this.NotFound());
            }

            txt.Title = model.Title;
            txt.Body  = model.Body;
            var publisher = mContext.Publishers.FirstOrDefault(a => a.Title.Equals(model.Publisher));

            if (publisher == null)
            {
                publisher = new Publisher()
                {
                    Title = model.Publisher
                };
                mContext.Publishers.Add(publisher);
            }
            var book = mContext.Books.FirstOrDefault(a => a.Publisher == publisher && a.Title.Equals(model.Book));

            if (book == null)
            {
                book = new Book()
                {
                    Title = model.Book, Publisher = publisher
                };
                mContext.Books.Add(book);
            }

            txt.Book = book;
            mContext.SaveChanges();
            return(Ok());
        }
        public ActionResult UpdateText(UpdateTextModel model, int id, int moduleId, string moduleFlag)
        {
            if (ModelState.IsValid && moduleId > 0)
            {
                var r = YunClient.Instance.Execute(new UpdateSiteElementTextRequest
                {
                    Id        = id,
                    Title     = model.Title,
                    Display   = Request.Form["Display"].TryTo(0) == 1,
                    HyperLink = model.HyperLink,
                    SortOrder = model.SortOrder,
                    ParentId  = model.ParentId
                }, Token);

                if (r.Result)
                {
                    ClearCache(moduleId);
                }

                return(Json(r.Result));
            }

            return(Json(false));
        }