Esempio n. 1
0
 public void EditDealer(DealerViewModel model)
 {
     if (model.Dealer.UserId > 0) {
         var dealer = DealerModel.ToDomainModel(model.Dealer);
         if (dealer.Id > 0) {
             masterService.UpdateDealer(dealer);
         } else {
             masterService.AddDealer(new[] { dealer });
         }
         //Add-Update Dealer-User Map
         var maps = userDealerMapService.FindUserDealerMaps(x => x.UserId == model.Dealer.UserId && x.DealerId == dealer.Id);
         if (maps.Any()) {
             var map = maps.First();
             map.UserId = model.Dealer.UserId;
             userDealerMapService.UpdateUserDealerMap(map);
         } else {
             userDealerMapService.AddUserDealerMap(new[] { new UserDealerMap { Id = 0, DealerId = dealer.Id, UserId = model.Dealer.UserId } });
         }
     }
 }
Esempio n. 2
0
        public void EditDealer(DealerViewModel model)
        {
            if (model.Dealer.UserIds == null)
                model.Dealer.UserIds = new List<int>();
            var dealer = DealerModel.ToDomainModel(model.Dealer);
            if (dealer.Id > 0)
            {
                masterService.UpdateDealer(dealer);
            }
            else
            {
                masterService.AddDealer(new[] { dealer });
            }
            //Add-Update Dealer-User Map

            var maps = userDealerMapService.FindUserDealerMaps(x => x.DealerId == dealer.Id).ToList();
            if (maps.Any())
            {
                var deleted = maps.Where(x => !(model.Dealer.UserIds.Contains(x.UserId)));
                foreach (var userDealerMap in deleted)
                {
                    userDealerMapService.DeleteUserDealerMap(userDealerMap.Id);
                }
                var added = model.Dealer.UserIds.Where(x => !(maps.Any(y => y.UserId == x))).Select(x => new UserDealerMap { UserId = x, DealerId = dealer.Id });
                userDealerMapService.AddUserDealerMap(added);

            }
            else
            {
                userDealerMapService.AddUserDealerMap(model.Dealer.UserIds.Select(x => new UserDealerMap { UserId = x, DealerId = dealer.Id }));
            }
        }
Esempio n. 3
0
 public ActionResult EditDealer(int id)
 {
     var dealer = id > 0 ? DealerModel.FromDomainModel(masterService.GetDealer(id)) : new DealerModel();
     var states = masterService.GetAllStates().Select(x => new KeyValuePair<int, string>(x.Id, x.Name)).ToList();
     var stateId = id > 0 ? dealer.StateId : (states.Any() ? states.First().Key : 0);
     var model = new DealerViewModel {
         Dealer = dealer,
         States = states,
         Users = GetCsmUserFromState(stateId).Select(x => new KeyValuePair<int, string>(x.Id, x.Name))
     };
     return PartialView("EditDealer", model);
 }
Esempio n. 4
0
        public ActionResult EditDealer(int id)
        {
            var domainDealer = masterService.GetDealer(id);
            var dealer = id > 0 ? DealerModel.FromDomainModel(domainDealer) : new DealerModel();
            var states = masterService.GetAllStates().Select(x => new KeyValuePair<int, string>(x.Id, x.Name)).OrderBy(x => x.Value).ToList();
            var stateId = id > 0 ? dealer.StateId : (states.Any() ? states.First().Key : 0);
            var assigned = new List<KeyValuePair<KeyValuePair<int, bool>, string>>();
            List<KeyValuePair<KeyValuePair<int, bool>, string>> notassigned;

            if (id != 0)
                assigned =
                    userService.FindUsers(x => domainDealer.UserDealerMaps.Any(y => y.UserId == x.Id)).OrderBy(x => x.Name).
                        Select(x => new KeyValuePair<KeyValuePair<int, bool>, string>(new KeyValuePair<int, bool>(x.Id, true), x.Name)).ToList();
            notassigned = GetCsmUserFromState(stateId).Where(x => !(assigned.Any(y => y.Key.Key == x.Id))).OrderBy(x => x.Name).
                   Select(x => new KeyValuePair<KeyValuePair<int, bool>, string>(new KeyValuePair<int, bool>(x.Id, false), x.Name)).ToList();

            assigned.AddRange(notassigned);
            var model = new DealerViewModel
            {
                Dealer = dealer,
                States = states,
                Users = assigned
            };
            return PartialView("EditDealer", model);
        }