public ActionResult Edit(int ProductGroup, int PersonRateGroup, int?RateListId)
 {
     if (!RateListId.HasValue)
     {
         RateListViewModel vm = _RateListService.GetNewRateListForWeaving(ProductGroup, PersonRateGroup);
         return(View("Create", vm));
     }
     else if (RateListId.Value >= 0)
     {
         RateListViewModel vm = _RateListService.GetRateListVM(RateListId.Value);
         return(View("Create", vm));
     }
     else
     {
         return(HttpNotFound());
     }
     //RateList s = _RateListService.Find(id);
     //if (s == null)
     //{
     //    return HttpNotFound();
     //}
     //PrepareViewBag();
     //return View("Create", s);
     //return View();
 }
 public void Initialize()
 {
     AddWeakEventListener(rateViewModel, RateViewModelPropertyChanged);
     IRateListView rateListView = container.GetExportedValue<IRateListView>();
     rateDataModels = new SynchronizingCollection<RateDataModel, Rate>(entityService.Rates, c => new RateDataModel(c));
     rateListViewModel = new RateListViewModel(rateListView, rateDataModels);
     AddWeakEventListener(rateListViewModel, RateListViewModelPropertyChanged);
     shellService.RateListView = rateListViewModel.View;
     shellService.RateView = rateViewModel.View;
     rateListViewModel.SelectedRate = rateListViewModel.Rates.FirstOrDefault();
 }
Esempio n. 3
0
        public ActionResult Rate(int id)
        {
            IEnumerable <Rate> rates = navigationProvider.GetRates();

            IEnumerable <Sport> sports = navigationProvider.GetSports();

            IEnumerable <Command> commands = navigationProvider.GetCommands();

            IEnumerable <Match> matches = navigationProvider.GetMatches();



            RateListViewModel ratesList = new RateListViewModel();

            var models = from r in rates
                         join m in matches on r.MatchId equals m.MatchId
                         join cH in commands on m.CommandIdHome equals cH.CommandId
                         join cG in commands on m.CommandIdGuest equals cG.CommandId
                         join s in sports on cH.SporttId equals s.SportId
                         where r.RateId == id
                         select new
            {
                RateId          = r.RateId,
                MatchId         = r.MatchId,
                WinCommandHome  = r.WinCommandHome,
                WinCommandGuest = r.WinCommandGuest,
                Draw            = r.Draw,
                CommandHome     = cH.Name,
                CommandGuest    = cG.Name,
                Date            = m.Date
            };


            ratesList.RateId          = models.First().RateId;
            ratesList.MatchId         = models.First().MatchId;
            ratesList.WinCommandGuest = models.First().WinCommandGuest;
            ratesList.WinCommandHome  = models.First().WinCommandHome;
            ratesList.Date            = models.First().Date;
            ratesList.Draw            = models.First().Draw;
            ratesList.CommandHome     = models.First().CommandHome;
            ratesList.CommandGuest    = models.First().CommandGuest;



            return(View(ratesList));
        }
        public RateListView()
        {
            InitializeComponent();

            reader.Read();
            rates = reader.Rates;

            foreach (Rate rate in rates)
            {
                dataModel = new RateDataModel(rate);
                dataModels.Add(dataModel);
            }

            viewModel = new RateListViewModel(this, dataModels);
            DataContext = viewModel;
            RunWorker();
        }
        public ActionResult Post(RateListViewModel vm)
        {
            RateList s = AutoMapper.Mapper.Map <RateListViewModel, RateList>(vm);


            if (ModelState.IsValid)
            {
                if (!vm.RateListId.HasValue || vm.RateListId.Value == 0)
                {
                    s.DocId        = vm.ProductGroupId;
                    s.DealUnitId   = UnitConstants.SqYard;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    _RateListService.Create(s);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag();
                        return(View("Create", vm));
                    }



                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
                else
                {
                    RateList tempRateList = _RateListService.Find(s.RateListId);

                    if (tempRateList.WEF > s.WEF)
                    {
                        ModelState.AddModelError("WEF", "Date cannot be older.");
                        return(View("Create", vm));
                    }

                    RateListHistory History = new RateListHistory();
                    History              = AutoMapper.Mapper.Map <RateList, RateListHistory>(tempRateList);
                    History.ObjectState  = Model.ObjectState.Added;
                    History.CreatedBy    = User.Identity.Name;
                    History.CreatedDate  = DateTime.Now;
                    History.ModifiedBy   = User.Identity.Name;
                    History.ModifiedDate = DateTime.Now;
                    new RateListHistoryService(_unitOfWork).Create(History);


                    tempRateList.Rate         = s.Rate;
                    tempRateList.WEF          = s.WEF;
                    tempRateList.Loss         = s.Loss;
                    tempRateList.UnCountedQty = s.UnCountedQty;
                    tempRateList.ModifiedDate = DateTime.Now;
                    tempRateList.ModifiedBy   = User.Identity.Name;
                    tempRateList.ObjectState  = Model.ObjectState.Modified;
                    _RateListService.Update(tempRateList);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag();
                        return(View("Create", vm));
                    }

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }