Exemplo n.º 1
0
        private void SetPublisherToEditAuthors(PublisherEditViewModel publisherToEdit, Publisher publisher)
        {
            var publisherAuthorsArray = publisher.Authors.ToArray();
            var existingAuthorsList   = _publisherService.GetExistingAuthors();

            var publisherToEditExistingAuthorsList = new List <Author>();

            for (int i = 0; i < publisherAuthorsArray.Length; i++)
            {
                if (i == publisher.Authors.ToArray().Length - 1)
                {
                    publisherToEdit.Authors += publisherAuthorsArray[i].Name;
                    break;
                }

                publisherToEdit.Authors += publisherAuthorsArray[i].Name + ";";
            }

            foreach (var existingAuthor in existingAuthorsList)
            {
                if (!publisher.Authors.Any(a => a.Name == existingAuthor.Name))
                {
                    publisherToEditExistingAuthorsList.Add(existingAuthor);
                }
            }

            publisherToEdit.ExistingAuthors = ConvertToSelectListAuthors(publisherToEditExistingAuthorsList);
        }
Exemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            _logger.Information("Action: Edit; Controller: Publisher; Call method: GET;");
            try
            {
                if (id == null)
                {
                    return(View("NotFound"));
                }

                PublisherEditViewModel publisherToEdit = new PublisherEditViewModel();
                var publisher = _publisherService.GetPublisherById(id.ToString());

                publisherToEdit.Id                       = publisher.Id;
                publisherToEdit.IsRemoved                = publisher.IsRemoved;
                publisherToEdit.Title                    = publisher.Title;
                publisherToEdit.Description              = publisher.Description;
                publisherToEdit.ExistingImagePath        = publisher.ImagePath;
                publisherToEdit.MonthlySubscriptionPrice = publisher.MonthlySubscriptionPrice;

                SetPublisherToEditTopics(publisherToEdit, publisher);
                SetPublisherToEditAuthors(publisherToEdit, publisher);

                return(View(publisherToEdit));
            }
            catch (Exception e) {
                LogException(e);

                return(RedirectToAction("Index", "Error", new { exceptionType = e.GetType().Name }));
            }
        }
Exemplo n.º 3
0
        private void SetPublisherToEditTopics(PublisherEditViewModel publisherToEdit, Publisher publisher)
        {
            var publisherTopicsArray = publisher.Topics.ToArray();
            var existingTopicsList   = _publisherService.GetExistingTopics();

            var publisherToEditExistingTopicsList = new List <Topic>();

            for (int i = 0; i < publisherTopicsArray.Length; i++)
            {
                if (i == publisher.Topics.ToArray().Length - 1)
                {
                    publisherToEdit.Topics += publisherTopicsArray[i].Title;
                    break;
                }

                publisherToEdit.Topics += publisherTopicsArray[i].Title + ";";
            }

            foreach (var existingTopic in existingTopicsList)
            {
                if (!publisher.Topics.Any(t => t.Title == existingTopic.Title))
                {
                    publisherToEditExistingTopicsList.Add(existingTopic);
                }
            }

            publisherToEdit.ExistingTopics = ConvertToSelectListTopics(publisherToEditExistingTopicsList);
        }
Exemplo n.º 4
0
        public IActionResult Edit(PublisherEditViewModel viewModel)
        {
            Publisher publisher = publisherService.GetByID(viewModel.Publisher.ID);

            publisher.Name = viewModel.Publisher.Name;

            publisherService.Update(publisher);
            return(RedirectToAction("Details", publisher));
        }
        public ActionResult EditProfile(PublisherEditViewModel model)
        {
            var publisher = new Publisher();

            Mapper.Map(model, publisher);

            _publisherService.EditPublisher(publisher);

            return(RedirectToAction("GetProfile"));
        }
Exemplo n.º 6
0
        public ActionResult Edit(PublisherEditViewModel model)
        {
            _logger.Information("Action: Edit; Controller: Publisher; Call method: POST;");
            try
            {
                var publisher = _publisherService.GetPublisherById(model.Id.ToString());

                if (!ModelState.IsValid)
                {
                    SetPublisherToEditAuthors(model, publisher);
                    SetPublisherToEditTopics(model, publisher);
                    return(View(model));
                }

                Publisher publisherToChanage = new Publisher
                {
                    Id          = model.Id,
                    IsRemoved   = model.IsRemoved,
                    Title       = model.Title,
                    Description = model.Description,
                    MonthlySubscriptionPrice = model.MonthlySubscriptionPrice
                };

                if (model.Image != null)
                {
                    if (!validImageTypes.Any(model.Image.ContentType.Contains))
                    {
                        SetPublisherToEditAuthors(model, publisher);
                        SetPublisherToEditTopics(model, publisher);

                        ModelState.AddModelError("", "Please choose either jpg, jpeg or png format file");
                        return(View(model));
                    }

                    publisherToChanage.ImagePath = GenerateImageSavePath(model.Image);
                }
                else
                {
                    publisherToChanage.ImagePath = model.ExistingImagePath;
                }

                publisherToChanage.Authors = ConvertToListAuthors(model.Authors);
                publisherToChanage.Topics  = ConvertToListTopics(model.Topics);

                string publisherToChangeId = _publisherService.UpdatePublisher(publisherToChanage);

                return(RedirectToAction("Details", "Publisher", new { id = publisherToChangeId }));
            } catch (Exception e) {
                LogException(e);

                return(RedirectToAction("Index", "Error", new { exceptionType = e.GetType().Name }));
            }
        }
Exemplo n.º 7
0
        public ActionResult AddPublisher(PublisherEditViewModel publisherEditViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(publisherEditViewModel));
            }

            var publisher = Mapper.Map <Publisher>(publisherEditViewModel);

            _publisherServices.Create(publisher);

            return(RedirectToAction("Index"));
        }
        public ActionResult EditProfile()
        {
            var publisherId = new Guid(User.Identity.GetUserId());

            var publisher = _publisherService.GetPublisher(publisherId);

            var model = new PublisherEditViewModel
            {
                CountrySelectList = EnumToSelectList <Country>()
            };

            Mapper.Map(publisher, model);

            return(View("EditPublisherProfile", model));
        }
        // GET: Publishers/Edit/5
        public async Task <IActionResult> Edit(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var publisher = await _context.Publishers.FindAsync(id);

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

            PublisherEditViewModel viewModel = _mapper.Map <PublisherEditViewModel>(publisher);

            return(PartialView("_EditPartial", viewModel));
        }
Exemplo n.º 10
0
        public IActionResult Edit(int id)
        {
            if (id == 0)
            {
                return(NotFound());
            }

            Publisher publisher = publisherService.GetByID(id);

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

            PublisherEditViewModel viewModel = new PublisherEditViewModel();

            viewModel.Publisher = publisher;

            return(View(viewModel));
        }
        public async Task <IActionResult> Edit(long id, [Bind("Id,ImageFile,Name,Description,IsActive")] PublisherEditViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Publisher publisher = _mapper.Map <Publisher>(viewModel);

                    if (viewModel.ImageFile != null)
                    {
                        _fileUpload.DeleteFile(viewModel.ExistingImage, uploadImagePath);

                        var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath);
                        publisher.Image = result.UniqueFileName;
                    }

                    _context.Update(publisher);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PublisherExists(viewModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(PartialView("_EditPartial", viewModel));
        }
Exemplo n.º 12
0
        public ActionResult AddPublisher()
        {
            var publisherEditViewModel = new PublisherEditViewModel();

            return(View(publisherEditViewModel));
        }