示例#1
0
        public CountryRegionViewModel(Entities.Region region)
        {
            Name         = region.Name;
            RegionID     = region.ID;
            SpawnEnabled = region.CanSpawn;

            var passages = region.Passages.ToList();

            passages = passages.Concat(region.Passages1).ToList();

            foreach (var passage in passages)
            {
                Passages.Add(new CountryRegionPassageViewModel(passage, region.ID));
            }

            Developement         = (double)region.Development;
            DefenseSystemQuality = region.DefenseSystemQuality;
            if (region.Hospital != null)
            {
                Hospital = new CountryRegionHospitalInformation(region.Hospital);
            }

            foreach (var resource in region.Resources.ToList())
            {
                Resources.Add(new RegionResourceViewModel(resource));
            }
        }
示例#2
0
 public void MapFrom(Models.RegionModel m, ref Entities.Region e)
 {
     e.Id         = m.Id;
     e.Text       = m.Text;
     e.CityId     = m.CityId;
     e.DistrictId = m.DistrictId;
     e.Status     = m.Status;
     e.NeighborId = m.NeighborId;
 }
示例#3
0
 public void MapFrom(Entities.Region e, ref Models.RegionModel m)
 {
     m.Id         = e.Id;
     m.Text       = e.Text;
     m.CityId     = e.CityId;
     m.DistrictId = e.DistrictId;
     m.Status     = e.Status;
     m.NeighborId = e.NeighborId;
 }
示例#4
0
 /// <summary>
 /// Updates an Existing Region record with a changed data
 /// </summary>
 /// <param name="id"></param>
 /// <param name="updatedRegion"></param>
 /// <returns></returns>
 public async Task <bool> UpdateRegion(string id, Entities.Region updatedRegion)
 {
     return(await _RegionStore.UpdateRegion(id, mapper.ConvertModelToRepo(updatedRegion).Result));
 }
示例#5
0
 /// <summary>
 /// Creates a new Region Type record
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public async Task CreateRegion(Entities.Region entity)
 {
     await _RegionStore.CreateRegion(mapper.ConvertModelToRepo(entity).Result);
 }
示例#6
0
        public void UpdateRegionToDB(List <RegionExcel> listRegion)
        {
            // Duyệt danh sách vùng, cập nhật vào database
            RegionService       regionService       = new RegionService();
            PlaceService        placeService        = new PlaceService();
            UserInRegionService userInRegionService = new UserInRegionService();
            List <RegionExcel>  listRegionLast      = listRegion;
            bool isUpdateLast = false;
            int  count        = listRegion.Count;

            for (int i = 0; i < count; i++)
            {
                RegionExcel item = listRegion[i];
                // Xử lý thêm, cập nhật danh sách vùng.
                Entities.Region entity = regionService.GetById(item.Id);
                entity.Text       = item.Text;
                entity.CityId     = item.CityId;
                entity.DistrictId = item.DistrictId;
                entity.Status     = item.Status == 1 ? true : false;
                entity.NeighborId = item.NeighborId;
                if (entity.Id > 0)
                {
                    // Update.
                    regionService.Update(entity);
                }
                else
                {
                    // Insert. lấy lại ID region.
                    entity.Id = regionService.Insert(entity);

                    // Cập nhật lại id vùng.
                    listRegionLast[i].Id = entity.Id;

                    // Cập nhật lại vùng lân cận.

                    listRegionLast.Where(r => r.NeighborId == item.Id).ToList().ForEach(r => r.NeighborId = entity.Id);

                    isUpdateLast = true;
                }

                // Xử lý cập nhật vào bảng Place.
                if (item.ListWard != "")
                {
                    string[] lstWard = item.ListWard.Split(',');
                    foreach (string ward in lstWard)
                    {
                        placeService.UpdateRegion(int.Parse(ward), entity.Id);
                    }
                }

                // Xử lý cập nhật vào bảng UserInRegion
                if (item.ListUser != "")
                {
                    // Lấy danh sách user của vùng cũ.
                    var lstUserOld   = regionService.ListUserItemByRegionId(item.Id);
                    var lstUserIDNew = item.ListUser.Split(',').ToList();
                    if (lstUserOld != null)
                    {
                        // Duyệt, xử lý dữ liệu cũ
                        foreach (var u in lstUserOld)
                        {
                            // Nếu danh sách mới mà không chứa ID user cũ thì xóa user đó đi.
                            // Cũng có thể chọn cách khác là cập nhật trạng thái, chuyển về Status = 0;
                            if (!lstUserIDNew.Contains(u.Id.ToString()))
                            {
                                userInRegionService.DeleteByUser(u.Id);
                            }
                        }
                    }

                    // Cập nhật những user mới.
                    Entities.UserInRegion userInRegion;
                    foreach (var uId in lstUserIDNew)
                    {
                        if (!lstUserOld.Any(x => x.Id.ToString() == uId))
                        {
                            userInRegion          = new Entities.UserInRegion();
                            userInRegion.UserId   = int.Parse(uId);
                            userInRegion.RegionId = entity.Id;
                            userInRegion.Status   = true;
                            userInRegionService.Save(userInRegion);
                            //userInRegionService.Insert(userInRegion);
                        }
                    }
                }
            }

            if (isUpdateLast)
            {
                UpdateRegionToDB(listRegionLast);
            }
        }
示例#7
0
        public ActionResult UpdateRegion(Models.RegionModel model)
        {
            if (ModelState.IsValid)
            {
                Entities.Region r = new Entities.Region();
                model.MapFrom(model, ref r);
                int result = 0;
                if (model.Id > 0)
                {
                    result = regionService.Update(r);
                }
                else
                {
                    result = regionService.Insert(r);
                }
                if (result <= 0)
                {
                    ViewBag.Message    = AdminConfigs.MESSAGE_UPDATE_ERROR;
                    ViewBag.AlertClass = AdminConfigs.CLASS_ALERT_DANGER;
                }
                else
                {
                    // Cập nhật lại ID vùng của xã, phường cũ.'
                    if (model.Id > 0)
                    {
                        foreach (Entities.Place p in placeService.ListWardInRegion(model.Id))
                        {
                            p.RegionId = null;
                            placeService.Update(p);
                        }
                    }

                    // Cập nhật lại id vùng của xã phường mới
                    Entities.Place e;
                    foreach (int wardId in model.WardOfRegionIds)
                    {
                        e          = placeService.GetById(wardId);
                        e.RegionId = result;
                        placeService.Update(e);
                    }

                    TempData[AdminConfigs.TEMP_MESSAGE]  = AdminConfigs.MESSAGE_UPDATE_SUCCESS;
                    TempData[AdminConfigs.TEMP_REDIRECT] = @Url.Action("Index2", "Region");

                    // Xóa đi những thông tin cơ bản của vùng
                    model.Text = "";
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                TempData[AdminConfigs.TEMP_MESSAGE] = AdminConfigs.MESSAGE_UPDATE_ERROR;
            }

            // Lấy danh sách Tỉnh/ Thành phố
            model.ListCity = placeService.ListPlaceItemByParent(0);

            // Lấy danh sách Quận Huyện
            model.ListDistrict = placeService.ListPlaceItemByParent(model.CityId);

            // Lấy danh sách xã phường đã lọc
            model.ListWardOfRegion   = placeService.ListPlaceItemByIds(model.WardOfRegionIds);
            model.ListWardOfDistrict = placeService.ListPlaceItemByIds(model.WardOfDistrictIds);

            model.ListRegion = regionService.ListItem();
            return(View(model));
        }