예제 #1
0
        public async Task <IActionResult> Edit(EditOfferViewModel input)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            string propertyId;

            try
            {
                propertyId = this.propertiesService.GetIdByOfferId(input.OfferId, user.Id);
            }
            catch (Exception ex)
            {
                this.TempData[GlobalConstants.ErrorMessages.PropertyAccessKey] = ex.Message;
                return(this.RedirectToAction("All", "Properties"));
            }

            this.ValidateCheckToDate(input);

            if (!this.ModelState.IsValid)
            {
                input.PropertyId   = propertyId;
                input.PropertyName = this.propertiesService.GetNameById(propertyId);
                input.CurrencyCode = this.currenciesService.GetByPropertyId(propertyId);

                return(this.View(input));
            }

            await this.offersService.UpdateAsync(input);

            this.TempData[GlobalConstants.SuccessMessages.EditOfferKey] = GlobalConstants.SuccessMessages.EditOfferValue;
            return(this.RedirectToAction("ById", "Properties", new { id = propertyId }));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Title, Description, SubjectNameId, Price, SharePriceOption, ImageUrl, Address")] EditOfferViewModel model)
        {
            try
            {
                var offerDto = mapper.Map <EditOfferViewModel, EditOfferDTO>(model);
                offerDto.Id = id;
                var result = await offerService.EditOffer(offerDto);

                var log = new Log
                {
                    UserId       = this.userManager.GetUserId(HttpContext.User),
                    LogType      = LogType.EditedAnOffer,
                    DateTime     = DateTime.Now,
                    ResourceId   = result,
                    ResourceType = ResourceType.Offer
                };
                int logResult = await logService.AddLog(log);

                this.TempData[Constants.ValidationState.Success] = Constants.Message.OfferUpdate.Success;
            }
            catch (Exception ex)
            {
                this.TempData[Constants.ValidationState.Error] = ex.Message;
            }

            return(this.RedirectToAction("Details", id));
        }
예제 #3
0
        public async Task UpdateAsync(EditOfferViewModel input)
        {
            var offer = this.offersRepository
                        .All()
                        .FirstOrDefault(o => o.Id == input.OfferId);

            offer.PricePerPerson = input.PricePerPerson;
            offer.ValidFrom      = (DateTime)input.ValidFrom;
            offer.ValidTo        = (DateTime)input.ValidTo;
            offer.Count          = input.Count;

            await this.offersRepository.SaveChangesAsync();
        }
예제 #4
0
        public ActionResult AddOffer(EditOfferViewModel model, HttpPostedFileBase file)
        {
            if (model.Offer.OfferId > 0)
            {
                // edit
                model.Offer.Status          = Models.OfferStatus.Oczekuje;
                model.Offer.UserId          = User.Identity.GetUserId();
                db.Entry(model.Offer).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("AddOffer", new { confirm = true }));
            }
            else
            {
                //add
                if (file != null && file.ContentLength > 0)
                {
                    if (ModelState.IsValid)
                    {
                        var fileExt  = Path.GetExtension(file.FileName);
                        var filename = Guid.NewGuid() + fileExt;
                        var path     = Path.Combine(Server.MapPath(AppConfig.CompanyPhotoSourceFolder), filename);
                        file.SaveAs(path);

                        model.Offer.CompanyPhotoSource = filename;
                        model.Offer.DateAdded          = DateTime.Now;
                        model.Offer.UserId             = User.Identity.GetUserId();
                        model.Offer.Status             = Models.OfferStatus.Oczekuje;

                        db.Offers.Add(model.Offer);
                        db.SaveChanges();

                        return(RedirectToAction("AddOffer", new { confirm = true }));
                    }
                    else
                    {
                        var categories = db.Categories.ToList();
                        model.Categories = categories;
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Nie wskazano pliku");
                    // in case of an error - the model will be forwarded, but without a category (to dropdown list)
                    var categories = db.Categories.ToList();
                    model.Categories = categories;
                    return(View(model));
                }
            }
        }
예제 #5
0
        public ActionResult Edit(EditOfferViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var offer = Mapper.Map <EditOfferViewModel, Offer>(model);

            using (var repo = new Repository <Offer>())
            {
                offer = repo.InsertOrUpdate(offer);
            }

            return(RedirectToAction("Detail", new { id = offer.Id }));
        }
예제 #6
0
        public async Task <IActionResult> Edit(string id)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            string propertyId;

            try
            {
                propertyId = this.propertiesService.GetIdByOfferId(id, user.Id);
            }
            catch (Exception ex)
            {
                this.TempData[GlobalConstants.ErrorMessages.PropertyAccessKey] = ex.Message;
                return(this.RedirectToAction("All", "Properties"));
            }

            EditOfferViewModel viewModel = this.offersService.GetById(id, user.Id);

            return(this.View(viewModel));
        }
예제 #7
0
 public IActionResult Update(int id, [FromBody] EditOfferViewModel viewModel)
 {
     try
     {
         _editOfferCommand.Execute(new EditOfferDto()
         {
             Amount = viewModel.Amount,
             Id     = id,
             UserId = GetUserId().Result
         });
         return(StatusCode(201));
     }
     catch (EntityNotFoundException e)
     {
         return(UnprocessableEntity(e.Message));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
예제 #8
0
        public ActionResult AddOffer(int?offerId, bool?confirm)
        {
            Offer offer;

            if (offerId.HasValue)
            {
                ViewBag.EditMode = true;
                offer            = db.Offers.Find(offerId);
            }
            else
            {
                ViewBag.EditMode = false;
                offer            = new Offer();
            }

            var result = new EditOfferViewModel();

            result.Categories = db.Categories.ToList();
            result.Offer      = offer;
            //confirm when [HttpPost] AddOfffer succeed
            result.Confirm = confirm;

            return(View(result));
        }
예제 #9
0
        public ActionResult Edit(EditOfferViewModel model, HttpPostedFileBase[] images)
        {
            //EditOfferViewModel model = new EditOfferViewModel();

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Buy", new { id = model.Id }));
            }
            var currentUserId = User.Identity.GetUserId();

            var userProfile = _userProfileService.GetUserProfiles(u => u.Id == currentUserId, i => i.ApplicationUser).SingleOrDefault();

            if (userProfile != null)
            {
                var appUser = userProfile.ApplicationUser;
                if (appUser != null)
                {
                    if (!(appUser.EmailConfirmed))
                    {
                        return(HttpNotFound("you are not confirmed email or phone number"));
                    }
                }
            }
            else
            {
                return(View("_CreateOfferConfirmationError"));
            }
            var offer = _offerService.GetOffer(model.Id, o => o.Game, o => o.Filters, o => o.FilterItems);

            if (offer.UserProfileId == User.Identity.GetUserId() && offer.State == OfferState.active)
            {
                Game game = _gameService.GetGameByValue(model.Game);
                offer.Price = model.Price;
                offer.SellerPaysMiddleman = model.SellerPaysMiddleman;
                offer.Game        = game;
                offer.Discription = model.Discription;
                offer.Header      = model.Header;


                var gameFilters      = _filterService.GetFilters(f => f.Game.Value == game.Value, i => i.FilterItems).ToList();
                var modelFilters     = model.FilterValues;
                var modelFilterItems = model.FilterItemValues;
                if (game != null && modelFilters.Length == gameFilters.Count)
                {
                    offer.FilterItems.Clear();
                    offer.Filters.Clear();
                    for (int i = 0; i < gameFilters.Count; i++)
                    {
                        if (gameFilters[i].Value != modelFilters[i])
                        {
                            return(View("_CreateOfferFilterError"));
                        }

                        bool isContainsFilterItems = false;
                        foreach (var fItem in gameFilters[i].FilterItems)
                        {
                            if (fItem.Value == modelFilterItems[i])
                            {
                                offer.FilterItems.Add(fItem);
                                offer.Filters.Add(gameFilters[i]);
                                isContainsFilterItems = true;
                            }
                        }
                        if (!isContainsFilterItems)
                        {
                            return(View("_CreateOfferFilterError"));
                        }
                    }
                }
                else
                {
                    return(View("_CreateOfferFilterError"));
                }

                for (int i = 0; i < offer.ScreenshotPathes.Count; i++)
                {
                    try
                    {
                        if (images[i] != null && images[i].ContentLength <= 1000000 && (images[i].ContentType == "image/jpeg" || images[i].ContentType == "image/png"))
                        {
                            if (offer.ScreenshotPathes[i].Value != null)
                            {
                                System.IO.File.Delete(Server.MapPath(offer.ScreenshotPathes[i].Value));
                            }


                            var extName  = System.IO.Path.GetExtension(images[i].FileName);
                            var fileName = $@"{Guid.NewGuid()}{extName}";
                            // сохраняем файл в папку Files в проекте
                            string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "\\Content\\Images\\Screenshots", fileName);
                            var    urlPath  = Url.Content("~/Content/Images/Screenshots/" + fileName);
                            try
                            {
                                images[i].SaveAs(fullPath);
                            }
                            catch (Exception)
                            {
                                return(HttpNotFound());
                            }
                            offer.ScreenshotPathes[i].Value = urlPath;
                        }
                    }
                    catch (Exception)
                    {
                        return(HttpNotFound());
                    }
                }

                _offerService.SaveOffer();

                return(RedirectToAction("Buy"));
            }

            return(HttpNotFound());
        }