Exemplo n.º 1
0
        public async Task <GroupZoneResponse> PostGroupZone(GroupZoneRequest model, int brandId)
        {
            try
            {
                List <Geometry> geoms;
                if (model.Type == (int)GroupZoneType.Ward)
                {
                    geoms = await _unitOfWork.Repository <Ward>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync();
                }
                else if (model.Type == (int)GroupZoneType.District)
                {
                    geoms = await _unitOfWork.Repository <District>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync();
                }
                else
                {
                    geoms = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync();
                }
                Geometry groupZoneGeom = (geoms.Any()) ? GeoJsonHelper.CombineGeoCollection(geoms) : null;
                var      insertItem    = new GroupZone()
                {
                    BrandId = brandId,
                    Geom    = groupZoneGeom,
                    Name    = model.Name,
                };
                await _unitOfWork.Repository <GroupZone>().InsertAsync(insertItem);

                await _unitOfWork.CommitAsync();

                return(new GroupZoneResponse()
                {
                    Id = insertItem.Id, Geom = insertItem.Geom, BrandId = insertItem.BrandId, Name = insertItem.Name
                });
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Insert Groupzone Error!!!", e.InnerException?.Message);
            }
        }
Exemplo n.º 2
0
        private void SaveCurrentGroup()
        {
            if (IsNew)
            {
                currentGroup.Name        = txtName.Text;
                currentGroup.Description = txtDescription.Text;

                Groups.InsertGroup(currentGroup);
                foreach (ListViewItem item in lvGroupZones.Items)
                {
                    GroupZone zone = item.Tag as GroupZone;
                    zone.GroupID = currentGroup.ID;

                    GroupZones.InsertZone(zone);
                }
                foreach (ListViewItem item in lvGroupSchedules.Items)
                {
                    GroupSchedule schedule = item.Tag as GroupSchedule;
                    schedule.GroupID = currentGroup.ID;

                    GroupSchedules.InsertSchedule(schedule);
                }

                var groups = Groups.GetAllGroups();

                lvGroups.BeginUpdate();

                lvGroups.Items.Clear();

                groups.ForEach(group =>
                {
                    ListViewItem item = new ListViewItem(new string[] { group.Name, group.Description });
                    item.Tag          = group;
                    lvGroups.Items.Add(item);

                    if (group.ID == currentGroup.ID)
                    {
                        item.Selected = true;
                    }
                });

                lvGroups.EndUpdate();
            }
            else
            {
                if (HasGroupChanges)
                {
                    currentGroup.Name        = txtName.Text;
                    currentGroup.Description = txtDescription.Text;

                    Groups.UpdateGroup(currentGroup);

                    lvGroups.SelectedItems[0].Text             = currentGroup.Name;
                    lvGroups.SelectedItems[0].SubItems[1].Text = currentGroup.Description;
                }
                if (HasZonesChanges)
                {
                    GroupZones.DeleteZones(currentGroup.ID);

                    foreach (ListViewItem item in lvGroupZones.Items)
                    {
                        GroupZone zone = item.Tag as GroupZone;
                        GroupZones.InsertZone(zone);
                    }
                }
                if (HasSchedulesChanges)
                {
                    GroupSchedules.DeleteSchedules(currentGroup.ID);

                    foreach (ListViewItem item in lvGroupSchedules.Items)
                    {
                        GroupSchedule schedule = item.Tag as GroupSchedule;
                        GroupSchedules.InsertSchedule(schedule);
                    }
                }
            }
        }