コード例 #1
0
        public ActionResult Collect(CollectViewModel viewModel)
        {
            var booking = _bookingRepository.GetByBookingNumber(viewModel.BookingNumber);
            var request = _collectViewModelMapper.Map(viewModel);

            if (booking == null)
            {
                ModelState.AddModelError("BookingNumber", "No booking could be found matching the specified booking number.");
            }
            else
            {
                var validationMessages = booking.ValidateCollect(request);
                validationMessages.ForEach(validationMessage => ModelState.AddModelError(validationMessage.Field, validationMessage.Text));
            }

            if (!ModelState.IsValid)
            {
                //_makeViewModelMapper.Hydrate(viewModel);
                return(View("Collect", viewModel));
            }

            booking.Collect(request);
            _bookingRepository.Update(booking);
            return(RedirectToAction("CollectSuccess"));
        }
コード例 #2
0
        public ActionResult Confirm(int id, string uniqueRadio, string fname, CollectViewModel model)
        {
            using (var collectService = new CollectsService())
            {
                try
                {
                    int selectedId = Int32.Parse(model.Gift.Id);
                    if (ModelState.IsValid)
                    {
                        collectService.ChangeRadioButtonChoose(id, GetUserId(), model.Gift.Id);
                    }
                    collectService.CollectAmountChange(id, model.Amount);
                    collectService.CollectConfirmChange(id, true);

                    //Send Email
                    using (var userService = new UsersService())
                    {
                        var collect = collectService.GetCollect(id);

                        collectService.SendEmailsConfirm(userService.GetUserIndex().Where(i => i.Id != collect.RecipientId).ToList(), collect);
                    }

                    return(RedirectToAction("Details", "Collects", new { id = id }));
                }
                catch (NullReferenceException)
                {
                    ViewBag.MustChooseItem = "Musisz wybrać jakikolwiek prezent !";
                }

                var collectViewModel = collectService.GetCollectViewModel(id, GetUserId());

                return(View(collectViewModel));
            }
        }
コード例 #3
0
        public CollectBookingRequest Map(CollectViewModel viewModel)
        {
            var request = new CollectBookingRequest();

            request.Mileage = viewModel.Mileage;
            var username = _userProvider.GetUsername();

            request.LoggedBy = _userRepository.GetByUsername(username);
            return(request);
        }
コード例 #4
0
        // GET: Collect/Delete/5
        public ActionResult Delete(int id)
        {
            var collection        = (Collect)service.GetByIdCollect(id);
            CollectViewModel item = new CollectViewModel();

            item.CollectName        = collection.CollectName;
            item.CollectDescription = collection.CollectDescription;
            item.CollectType        = collection.CollectType;
            return(View(item));
        }
コード例 #5
0
        // GET: Collect/Create
        public ActionResult Create()
        {
            var           eventVM = new CollectViewModel();
            List <string> types   = new List <string> {
                "Charity", "Food", "Collect"
            };

            eventVM.CollectTypes = types.ToSelectListItems();

            return(View(eventVM));
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: xiazhaowei/hmh
        public ActionResult CheckCollect(CollectViewModel model)
        {
            model.CheckNotNull(nameof(model));
            if (CurrentUser == null)
            {
                return(Json(new AjaxResult("未登录", AjaxResultType.Error)));
            }
            Collect collect = IdentityContract.Collects.SingleOrDefault(c => c.User.Id == CurrentUser.Id && c.AboutId == model.AboutId && c.Type == CollectType.Goods);

            if (collect == null)
            {
                return(Json(new AjaxResult("收藏", AjaxResultType.Error)));
            }
            return(Json(new AjaxResult("已收藏", AjaxResultType.Success)));
        }
コード例 #7
0
        public ActionResult Details(int id, CollectViewModel model)
        {
            using (var collectService = new CollectsService())
            {
                ViewBag.InCollect = collectService.IsCollectionsUser(id, GetUserId());

                if (ModelState.IsValid)
                {
                    collectService.ChangeRadioButtonChoose(id, GetUserId(), model.Gift.Id);
                }

                var collectViewModel = collectService.GetCollectViewModel(id, GetUserId());
                return(View(collectViewModel));
            }
        }
コード例 #8
0
        public ActionResult Edit(int id, CollectViewModel collection)
        {
            var           eventVM = new CollectViewModel();
            List <string> types   = new List <string> {
                "Charity", "Food", "Collect"
            };

            eventVM.CollectTypes = types.ToSelectListItems();
            Collect e = (Collect)service.GetByIdCollect(id);

            e.CollectName        = collection.CollectName;
            e.CollectDescription = collection.CollectDescription;
            e.CollectType        = collection.CollectType;

            service.UpdateCollect(e);
            service.SaveChange();
            return(RedirectToAction("Index"));
        }
コード例 #9
0
        // GET: Collect/Edit/5
        public ActionResult Edit(int id)
        {
            var           eventVM = new CollectViewModel();
            List <string> types   = new List <string> {
                "Charity", "Food", "Collect"
            };

            eventVM.CollectTypes = types.ToSelectListItems();
            Collect e = (Collect   )service.GetByIdCollect(id);
            // Event ev = new Event
            CollectViewModel em = new CollectViewModel();

            {
                em.CollectName        = e.CollectName;
                em.CollectDescription = e.CollectDescription;
                em.CollectType        = e.CollectType;
            };
            return(View(em));
        }
コード例 #10
0
        //Details
        public CollectViewModel GetCollectViewModel(int collectId, int userId)
        {
            var collect = GetCollect(collectId);

            double NumberUsersInCollect = _unitOfWork.CollectUserRepository.Get().Count(c => c.CollectId == collectId);
            double MyAmount             = _unitOfWork.CollectRepository.Get().SingleOrDefault(c => c.Id == collectId).Amount;
            double AmountPerPerson      = MyAmount / NumberUsersInCollect;

            CollectViewModel collectViewModel = new CollectViewModel();

            collectViewModel.Id                         = collect.Id;
            collectViewModel.UserId                     = userId;
            collectViewModel.Name                       = collect.Name;
            collectViewModel.OwnerId                    = collect.OwnerId.Value;
            collectViewModel.RecipientId                = collect.RecipientId.Value;
            collectViewModel.OwnerName                  = collect.Owner.Name;
            collectViewModel.RecipientName              = collect.Recipient.Name;
            collectViewModel.Description                = collect.Description;
            collectViewModel.Amount                     = collect.Amount;
            collectViewModel.IsConfirmed                = collect.IsConfirmed;
            collectViewModel.DateOfInitiative           = collect.DateOfInitiative.Value;
            collectViewModel.DateOfAdd                  = collect.DateOfAdd.Value;
            collectViewModel.RadioGiftItems             = AllRadioGiftList(collectId, userId).OrderByDescending(i => i.Rating).ToList();
            collectViewModel.Users                      = AllCollectUsersGaveMoney(collect.Id);
            collectViewModel.PossibilityEditCollectGift = GetPossibilityEditCollectGift(collectId);
            if (_unitOfWork.CollectGiftRatingRepository.Get().Any(c => c.CollectId == collectId && c.UserId == userId && c.TheBestGiftId != null))
            {
                int GiftId = _unitOfWork.CollectGiftRatingRepository.Get().FirstOrDefault(c => c.CollectId == collectId && c.UserId == userId).TheBestGiftId.Value;
                collectViewModel.GiftName = _unitOfWork.CollectGiftRepository.Get().Single(i => i.Id == GiftId).Name;
            }
            else
            {
                collectViewModel.GiftName = "Null Gift Name";
            }
            collectViewModel.AmountPerPerson = AmountPerPerson;

            return(collectViewModel);
        }
コード例 #11
0
        public ActionResult Create(CollectViewModel e, HttpPostedFileBase Image)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Create"));
            }
            // TODO: Add insert logic here
            //  e.EventImg = Image.FileName;

            Collect ev = new Collect
            {
                CollectID          = e.CollectID,
                CollectName        = e.CollectName,
                CollectDescription = e.CollectDescription,
                CollectType        = e.CollectType,
            };

            service.AddCollect(ev);
            service.SaveChange();
            //Sms
            new SsmsService().SendSms(new Sms("+216" + ev.CollectType, "We have a donation for you"));

            return(RedirectToAction("Index"));
        }
コード例 #12
0
        public CollectViewModel New()
        {
            var viewModel = new CollectViewModel();

            return(viewModel);
        }
コード例 #13
0
 public NewGarmentWindow(CollectViewModel collectViewModel)
 {
     this.DataContext = new NewGarmentViewModel(this.Close, collectViewModel);
     InitializeComponent();
 }
コード例 #14
0
ファイル: AccountController.cs プロジェクト: xiazhaowei/hmh
        public ActionResult DoCollect(CollectViewModel model)
        {
            model.CheckNotNull(nameof(model));
            if (CurrentUser == null)
            {
                return(Json(new AjaxResult("未登录", AjaxResultType.Error)));
            }
            //获取收藏类型
            CollectType collectType = GetCollectType(model.Type);
            //检查收藏状态
            Collect collect = IdentityContract.Collects.SingleOrDefault(c => c.User.Id == CurrentUser.Id && c.AboutId == model.AboutId && c.Type == collectType);

            if (collect == null)
            {
                CollectInputDto dto = new CollectInputDto()
                {
                    UserId  = CurrentUser.Id,
                    AboutId = model.AboutId,
                    Pic     = "default",
                    Type    = collectType
                };

                if (collectType == CollectType.Goods)
                {
                    //检查商品
                    Hmh.Core.Goods.Models.Goods goods = GoodsContract.Goodss.SingleOrDefault(g => g.Id == model.AboutId);
                    if (goods == null)
                    {
                        return(Json(new AjaxResult("错误商品不存在", AjaxResultType.Error)));
                    }
                    dto.Name = goods.Name;
                }
                else
                {
                    //检查店铺
                    Hmh.Core.Shop.Models.Shop shop = ShopContract.Shops.SingleOrDefault(s => s.Id == model.AboutId);
                    if (shop == null)
                    {
                        return(Json(new AjaxResult("错误店铺不存在", AjaxResultType.Error)));
                    }
                    dto.Name = shop.Name;
                }

                OperationResult result = IdentityContract.AddCollects(dto);
                if (result.ResultType == OperationResultType.Success)
                {
                    return(Json(new AjaxResult("已收藏", AjaxResultType.Success)));
                }
                else
                {
                    return(Json(new AjaxResult("失败", AjaxResultType.Error)));
                }
            }
            else
            {
                OperationResult result = IdentityContract.DeleteCollects(collect.Id);
                if (result.ResultType == OperationResultType.Success)
                {
                    return(Json(new AjaxResult("收藏", AjaxResultType.Success)));
                }
                else
                {
                    return(Json(new AjaxResult("失败", AjaxResultType.Error)));
                }
            }
        }