Exemplo n.º 1
0
        public AddNewPinViewModel(Position position)
        {
            _mapCenter     = position;
            ValidCities    = new List <DeserializeCitiesData>();
            _pinCategories = new ObservableCollection <PinCategory>(ApplicationSettings.PinCategories.Select(item =>
            {
                var temp = new PinCategory
                {
                    CategoriesBranch = item.CategoriesBranch,
                    Color            = item.Color,
                    Icon             = item.Icon,
                    Id           = item.Id,
                    PinIcon      = item.PinIcon,
                    IsVisible    = true,
                    ItemSelected = false,
                    Name         = item.Name,
                    ParentId     = item.ParentId
                };
                temp.ItemTapped += Category_ItemTapped;
                return(temp);
            }));
            _pinSubCategories = new ObservableCollection <PinCategory>(ApplicationSettings.PinSubCategories.Select(item =>
            {
                var temp = new PinCategory
                {
                    CategoriesBranch = item.CategoriesBranch,
                    Color            = item.Color,
                    Icon             = item.Icon,
                    PinIcon          = item.PinIcon,
                    Id           = item.Id,
                    IsVisible    = false,
                    ItemSelected = false,
                    Name         = item.Name,
                    ParentId     = item.ParentId
                };
                temp.ItemTapped += Tag_ItemTapped;
                return(temp);
            }));
            _weekViewModel     = new WeekViewModel();
            _baseCategoryImage = "empty_object_icon.png";
            //_photo = "add_picture_btn.png";
            _workTimeViewModels = new List <WorkTimeViewModel>();
            _phoneViewModels    = new List <PhoneViewModel>();
            var firstWoktimeVm = new WorkTimeViewModel(new List <MyDayOfWeek>(), true);

            firstWoktimeVm.PlusMinusClicked += WoktimeVm_PlusMinusClicked;
            firstWoktimeVm.CalendarClicked  += WoktimeVm_CalendarClicked;
            _workTimeViewModels.Add(firstWoktimeVm);
            var firstPhone = new PhoneViewModel(new Phone {
                Primary = true
            }, true);

            firstPhone.PlusMinusClicked += Phone_PlusMinusClicked;
            _phoneViewModels.Add(firstPhone);
            _isRedact = false;
            Photos.CollectionChanged += Photos_CollectionChanged;
        }
Exemplo n.º 2
0
        public AddNewPinViewModel(UserPinDescriptor pin)
        {
            Pin            = pin;
            _mapCenter     = new Position(pin.Lat, pin.Lng);
            ValidCities    = new List <DeserializeCitiesData>();
            _pinCategories = new ObservableCollection <PinCategory>(ApplicationSettings.PinCategories.Select(item =>
            {
                var temp = new PinCategory
                {
                    CategoriesBranch = item.CategoriesBranch,
                    Color            = item.Color,
                    Icon             = item.Icon,
                    Id           = item.Id,
                    PinIcon      = item.PinIcon,
                    IsVisible    = true,
                    ItemSelected = false,
                    Name         = item.Name,
                    ParentId     = item.ParentId
                };
                temp.ItemTapped += Category_ItemTapped;
                return(temp);
            }));
            _pinSubCategories = new ObservableCollection <PinCategory>(ApplicationSettings.PinSubCategories.Select(item =>
            {
                var temp = new PinCategory
                {
                    CategoriesBranch = item.CategoriesBranch,
                    Color            = item.Color,
                    Icon             = item.Icon,
                    PinIcon          = item.PinIcon,
                    Id           = item.Id,
                    IsVisible    = false,
                    ItemSelected = false,
                    Name         = item.Name,
                    ParentId     = item.ParentId
                };
                temp.ItemTapped += Tag_ItemTapped;
                return(temp);
            }));

            foreach (var item in _pinSubCategories.Where(psc => psc.ParentId == Pin.BaseCategoryId))
            {
                item.IsVisible    = true;
                item.ItemSelected = Pin.Subcategories.Any(p => p.Id == item.Id);
            }

            OldPhotos = new ObservableCollection <string>(pin.PhotosMini);

            #region [ Для времени работы ]

            _weekViewModel = new WeekViewModel();

            _workTimeViewModels = new List <WorkTimeViewModel>();

            if (Pin.WorkTime != null && Pin.WorkTime.Count > 0)
            {
                foreach (var tempListOfDay in Pin.WorkTime.GroupBy(w => w.CloseTime.ToString() + w.OpenTime.ToString()))
                {
                    var newWorkTimeViewModel = new WorkTimeViewModel();
                    if (_workTimeViewModels.All(wt => !wt.IsAdd))
                    {
                        newWorkTimeViewModel.IsAdd = true;
                    }
                    newWorkTimeViewModel.PlusMinusClicked += WoktimeVm_PlusMinusClicked;
                    newWorkTimeViewModel.CalendarClicked  += WoktimeVm_CalendarClicked;
                    foreach (var workTime in tempListOfDay)
                    {
                        newWorkTimeViewModel.Days.Add(new MyDayOfWeek((DayOfWeek)(workTime.Id == 7 ? 0 : workTime.Id))
                        {
                            IsSelected = true
                        });
                        newWorkTimeViewModel.StartTime = workTime.OpenTime;
                        newWorkTimeViewModel.StopTime  = workTime.CloseTime;
                        _weekViewModel.Days.FirstOrDefault(
                            d => d.Day == (DayOfWeek)(workTime.Id == 7 ? 0 : workTime.Id))
                        .IsSelected = true;
                    }
                    _workTimeViewModels.Add(newWorkTimeViewModel);
                }
            }
            else
            {
                var firstWoktimeVm = new WorkTimeViewModel(new List <MyDayOfWeek>(), true);
                firstWoktimeVm.PlusMinusClicked += WoktimeVm_PlusMinusClicked;
                firstWoktimeVm.CalendarClicked  += WoktimeVm_CalendarClicked;
                _workTimeViewModels.Add(firstWoktimeVm);
            }

            #endregion [ Для времени работы ]

            #region [ Для телефонов ]

            _phoneViewModels = new List <PhoneViewModel>();
            if (Pin.Phones != null && Pin.Phones.Count > 0)
            {
                foreach (var phone in Pin.Phones)
                {
                    var newPhone = new PhoneViewModel(phone);
                    if (newPhone.Phone.Primary)
                    {
                        newPhone.IsAdd = true;
                    }
                    _phoneViewModels.Add(newPhone);
                    newPhone.PlusMinusClicked += Phone_PlusMinusClicked;
                }
            }
            else
            {
                var firstPhone = new PhoneViewModel(new Phone {
                    Primary = true
                }, true);
                firstPhone.PlusMinusClicked += Phone_PlusMinusClicked;
                _phoneViewModels.Add(firstPhone);
            }

            #endregion [ Для телефонов ]

            _baseCategoryString  = Pin.BaseCategoryName;
            _baseCategoryColor   = _pinCategories.FirstOrDefault(c => c.Id == Pin.BaseCategoryId).Color;
            _baseCategoryImage   = _pinCategories.FirstOrDefault(c => c.Id == Pin.BaseCategoryId).Icon;
            BaseCategorySelected = true;
            PinCategories.FirstOrDefault(c => c.Id == Pin.BaseCategoryId).ItemSelected = true;
            _isRedact = true;
            Photos.CollectionChanged += Photos_CollectionChanged;
            PropertyChanged          += AddNewPinViewModel_PropertyChanged;
            Pin.PropertyChanged      += Pin_PropertyChanged;
        }
Exemplo n.º 3
0
 public ActionResult CategoryEdit(string act = "", int id = 0, int aId = 0, int storeId = 0, PinCategory model = null, int fid = 0)
 {
     //参数验证
     if (id < 0 || aId <= 0)
     {
         result.msg = "参数错误";
         return(Json(result));
     }
     //显示
     if (string.IsNullOrEmpty(act))
     {
         if (id == 0)
         {
             model = new PinCategory();
         }
         else
         {
             model = PinCategoryBLL.SingleModel.GetModel(id);
             if (model == null)
             {
                 return(Content("对象不存在"));
             }
         }
         EditModel <PinCategory> em = new EditModel <PinCategory>();
         em.DataModel = model;
         em.aId       = aId;
         em.storeId   = storeId;
         return(View(em));
     }
     else
     {
         if (act == "edit")
         {
             ModelState.Remove("sort");
             if (!ModelState.IsValid)
             {
                 result.code = 0;
                 result.msg  = this.ErrorMsg();
                 return(Json(result));
             }
             if (id == 0)
             {
                 if (PinCategoryBLL.SingleModel.Exists($"state=1 and aid={aId} and storeid={storeId} and name=@name", new MySql.Data.MySqlClient.MySqlParameter[] {
                     new MySql.Data.MySqlClient.MySqlParameter("@name", model.name)
                 }))
                 {
                     result.code = 0;
                     result.msg  = $"“{ model.name}” 已存在,不能重复添加!";
                     return(Json(result));
                 }
                 int newid = Convert.ToInt32(PinCategoryBLL.SingleModel.Add(model));
                 result.msg  = newid > 0 ? "添加成功" : "添加失败";
                 result.code = newid > 0 ? 1 : 0;
             }
             else
             {
                 if (PinCategoryBLL.SingleModel.Exists($"state=1 and aid={aId} and storeid={storeId} and name=@name and id<>{id}", new MySql.Data.MySqlClient.MySqlParameter[] {
                     new MySql.Data.MySqlClient.MySqlParameter("@name", model.name)
                 }))
                 {
                     result.code = 0;
                     result.msg  = $"“{ model.name}” 已存在,不能重复添加!";
                     return(Json(result));
                 }
                 bool updateResult = PinCategoryBLL.SingleModel.Update(model);
                 result.msg  = updateResult ? "修改成功" : "修改失败";
                 result.code = updateResult ? 1 : 0;
             }
         }
     }
     return(Json(result));
 }
Exemplo n.º 4
0
 public ActionResult Category(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20, string sortData = "", int fid = 0, int state = 1)
 {
     //显示
     if (string.IsNullOrEmpty(act))
     {
         string filterSql           = $"state<>-1 and aid={aId} and storeid={storeId} and fId={fid}";
         ViewModel <PinCategory> vm = new ViewModel <PinCategory>();
         vm.DataList   = PinCategoryBLL.SingleModel.GetList(filterSql, pageSize, pageIndex, "*", "sort desc");
         vm.TotalCount = PinCategoryBLL.SingleModel.GetCount(filterSql);
         vm.PageIndex  = pageIndex;
         vm.PageSize   = pageSize;
         vm.aId        = aId;
         vm.storeId    = storeId;
         return(View(vm));
     }
     else
     {
         //删除
         if (act == "del")
         {
             if (id <= 0)
             {
                 result.msg = "参数错误";
             }
             else
             {
                 PinCategory updateModel = PinCategoryBLL.SingleModel.GetModel(id);
                 if (updateModel != null)
                 {
                     updateModel.state = -1;
                     bool updateResult = PinCategoryBLL.SingleModel.Update(updateModel);
                     if (updateResult)
                     {
                         result.code = 1;
                         result.msg  = "删除成功";
                     }
                     else
                     {
                         result.msg = "删除失败";
                     }
                 }
                 else
                 {
                     result.msg = "删除失败,对象不存在或已删除";
                 }
             }
         }
         else if (act == "sort")
         {
             bool updateResult = PinCategoryBLL.SingleModel.UpdateSortBatch(sortData, aId);
             result.code = updateResult ? 1 : 0;
             result.msg  = updateResult ? "排序成功" : "排序失败";
         }
         else if (act == "updateState")
         {
             PinCategory model        = PinCategoryBLL.SingleModel.GetModel(id);
             bool        updateResult = false;
             if (model != null)
             {
                 model.state  = state;
                 updateResult = PinCategoryBLL.SingleModel.Update(model, "state");
             }
             result.code = updateResult ? 1 : 0;
             result.msg  = updateResult ? "设置成功" : "设置失败";
         }
     }
     return(Json(result));
 }