Ejemplo n.º 1
0
        public async Task AddTaluk(string stateId, string districtId, Taluk taluk)
        {
            var id = new ObjectId(stateId);

            taluk.Id       = ObjectId.GenerateNewId();
            taluk.Villages = new List <Village>();
            if (taluk.Feeders != null && taluk.Feeders.Any())
            {
                var feeder = taluk.Feeders.First();
                feeder.Id           = ObjectId.GenerateNewId();
                feeder.Transformers = new List <Transformer>();
            }
            else
            {
                taluk.Feeders = new List <Feeder>();
            }
            var did    = new ObjectId(districtId);
            var filter = Builders <State> .Filter.And(
                Builders <State> .Filter.Where(x => x.Id == id),
                Builders <State> .Filter.Eq("Districts.Id", did));

            var update = Builders <State> .Update.Push("Districts.$.Taluks", taluk);

            await this.states.FindOneAndUpdateAsync(filter, update);
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            Taluk taluk = db.Taluks.Find(id);

            db.Taluks.Remove(taluk);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 private void UpdateTalukFromModel(Taluk target, TalukModel source)
 {
     target.TalukId       = source.TalukId;
     target.TalukGuid     = source.TalukGuid;
     target.TalukName     = source.TalukName;
     target.TalukGMapLink = source.TalukGMapLink;
     target.TalukIsActive = source.TalukIsActive;
 }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,Name,DistrictId")] Taluk taluk)
 {
     if (ModelState.IsValid)
     {
         db.Entry(taluk).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DistrictId = new SelectList(DataFilter.GetDistricts(TempData.Peek("Id") + ""), "Id", "Name", taluk.DistrictId);
     return(View(taluk));
 }
Ejemplo n.º 5
0
 public IActionResult Post(int stateId, int districtId, [FromBody] Taluk taluk)
 {
     try
     {
         this.addressRepository.AddTaluk(stateId, districtId, taluk);
         return(this.Ok());
     }
     catch (Exception ex)
     {
         return(this.StatusCode(500));
     }
 }
        static public async Task <TalukModel> CreateTalukModelAsync(Taluk source, bool includeAllFields)
        {
            var model = new TalukModel()
            {
                TalukId       = source.TalukId,
                TalukGuid     = source.TalukGuid,
                TalukName     = source.TalukName,
                TalukGMapLink = source.TalukGMapLink,
                TalukIsActive = source.TalukIsActive,
            };

            return(model);
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Name,DistrictId")] Taluk taluk)
        {
            if (ModelState.IsValid)
            {
                taluk.Id = Guid.NewGuid();
                db.Taluks.Add(taluk);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DistrictId = new SelectList(DataFilter.GetDistricts(TempData.Peek("Id") + ""), "Id", "Name", taluk.DistrictId);
            return(View(taluk));
        }
Ejemplo n.º 8
0
        // GET: Taluks/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Taluk taluk = db.Taluks.Find(id);

            if (taluk == null)
            {
                return(HttpNotFound());
            }
            return(View(taluk));
        }
Ejemplo n.º 9
0
        // GET: Taluks/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Taluk taluk = db.Taluks.Find(id);

            if (taluk == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DistrictId = new SelectList(DataFilter.GetDistricts(TempData.Peek("Id") + ""), "Id", "Name", taluk.DistrictId);
            return(View(taluk));
        }
        public async Task <TalukModel> UpdateTalukAsync(TalukModel model)
        {
            long id = model.TalukId;

            using (var dataService = DataServiceFactory.CreateDataService())
            {
                var taluk = new Taluk();
                if (taluk != null)
                {
                    UpdateTalukFromModel(taluk, model);
                    await dataService.UpdateTalukAsync(taluk);

                    model.Merge(await GetTalukAsync(dataService, taluk.TalukId));
                }
                return(model);
            }
        }
        public async Task <int> UpdateTalukAsync(Taluk taluk)
        {
            if (taluk.TalukId > 0)
            {
                _dataSource.Entry(taluk).State = EntityState.Modified;
            }
            else
            {
                taluk.TalukGuid = Guid.NewGuid();
                //Company.CreatedOn = DateTime.UtcNow;
                _dataSource.Entry(taluk).State = EntityState.Added;
            }
            // Company.LastModifiedOn = DateTime.UtcNow;
            taluk.SearchTerms = taluk.BuildSearchTerms();
            int res = await _dataSource.SaveChangesAsync();

            return(res);
        }
        public async Task <int> AddTalukAsync(Taluk model)
        {
            if (model == null)
            {
                return(0);
            }

            var entity = new Taluk()
            {
                TalukId       = model.TalukId,
                TalukGuid     = model.TalukGuid,
                TalukName     = model.TalukName,
                TalukGMapLink = model.TalukGMapLink,
                TalukIsActive = model.TalukIsActive
            };

            _dataSource.Entry(entity).State = EntityState.Added;
            int res = await _dataSource.SaveChangesAsync();

            return(res);
        }
Ejemplo n.º 13
0
        public void AddTaluk(int stateId, int districtId, Taluk taluk)
        {
            var data   = System.IO.File.ReadAllText(string.Format(configuration.AppSettings.DbTablesFilePath, "Address.json"));
            var states = JsonConvert.DeserializeObject <List <State> >(data);

            if (states.Any())
            {
                var state    = states.FirstOrDefault(p => p.Id == stateId);
                var district = state.Districts.FirstOrDefault(p => p.Id == districtId);
                if (district != null)
                {
                    taluk.Villages = new List <Village>();
                    var tqs = states.SelectMany(p => p.Districts.SelectMany(q => q.Taluks));
                    var t   = tqs.Any() ? tqs.Max(p => p.Id) : 0;
                    taluk.Id = t + 1;

                    if (taluk.Feeders != null && taluk.Feeders.Any())
                    {
                        var feeder = taluk.Feeders.First();
                        feeder.Id           = FeederExtensions.GetNextFeederId(states);
                        feeder.Transformers = new List <Transformer>();
                        taluk.Feeders       = new List <Feeder> {
                            feeder
                        };
                    }
                    else
                    {
                        taluk.Feeders = new List <Feeder>();
                    }

                    var taluks = district.Taluks != null?district.Taluks.ToList() : new List <Taluk>();

                    taluks.Add(taluk);
                    district.Taluks = taluks;
                }
            }

            System.IO.File.WriteAllText(string.Format(configuration.AppSettings.DbTablesFilePath, "Address.json"), JsonConvert.SerializeObject(states));
        }
        public async Task <Result> DeleteTalukAsync(TalukModel model)
        {
            var taluk = new Taluk {
                TalukId = model.TalukId
            };

            using (var dataService = DataServiceFactory.CreateDataService())
            {
                try
                {
                    await dataService.DeleteTalukAsync(taluk);
                }
                catch (DbUpdateException ex) when(ex.InnerException is SqlException sqlException && (sqlException.Number == 547))
                {
                    return(Result.Error("Taluk is already in use"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(Result.Ok());
            }
        }
 public async Task <int> DeleteTalukAsync(Taluk taluk)
 {
     _dataSource.Taluks.Remove(taluk);
     return(await _dataSource.SaveChangesAsync());
 }
Ejemplo n.º 16
0
 private WoodVolume SetUpContract(WoodVolume contract)
 {
     if ((contract.division_id ?? 0) <= 0)
     {
         if (string.IsNullOrEmpty(contract.division_name) == false)
         {
             BaseRepository <Division, wvc_division> divisionRepository = new BaseRepository <Division, wvc_division>();
             Division division = divisionRepository.Find(new Division {
                 name = contract.division_name
             }).FirstOrDefault();
             if (division != null)
             {
                 contract.division_id = division.id;
             }
             else
             {
                 division = divisionRepository.Save(new Division {
                     name = contract.division_name
                 });
                 if (division != null)
                 {
                     contract.division_id = division.id;
                 }
             }
         }
     }
     if ((contract.district_id ?? 0) <= 0)
     {
         if (string.IsNullOrEmpty(contract.district_name) == false)
         {
             BaseRepository <District, wvc_district> districtRepository = new BaseRepository <District, wvc_district>();
             District district = districtRepository.Find(new District {
                 name = contract.district_name
             }).FirstOrDefault();
             if (district != null)
             {
                 contract.district_id = district.id;
             }
             else
             {
                 district = districtRepository.Save(new District {
                     name = contract.district_name
                 });
                 if (district != null)
                 {
                     contract.district_id = district.id;
                 }
             }
         }
     }
     if ((contract.range_id ?? 0) <= 0)
     {
         if (string.IsNullOrEmpty(contract.range_name) == false)
         {
             BaseRepository <Range, wvc_range> rangeRepository = new BaseRepository <Range, wvc_range>();
             Range range = rangeRepository.Find(new Range {
                 name = contract.range_name
             }).FirstOrDefault();
             if (range != null)
             {
                 contract.range_id = range.id;
             }
             else
             {
                 range = rangeRepository.Save(new Range {
                     name = contract.range_name
                 });
                 if (range != null)
                 {
                     contract.range_id = range.id;
                 }
             }
         }
     }
     if ((contract.taluk_id ?? 0) <= 0)
     {
         if (string.IsNullOrEmpty(contract.taluk_name) == false)
         {
             BaseRepository <Taluk, wvc_taluk> talukRepository = new BaseRepository <Taluk, wvc_taluk>();
             Taluk taluk = talukRepository.Find(new Taluk {
                 name = contract.taluk_name
             }).FirstOrDefault();
             if (taluk != null)
             {
                 contract.taluk_id = taluk.id;
             }
             else
             {
                 taluk = talukRepository.Save(new Taluk {
                     name = contract.taluk_name
                 });
                 if (taluk != null)
                 {
                     contract.taluk_id = taluk.id;
                 }
             }
         }
     }
     if ((contract.village_id ?? 0) <= 0)
     {
         if (string.IsNullOrEmpty(contract.village_name) == false)
         {
             BaseRepository <Village, wvc_village> villageRepository = new BaseRepository <Village, wvc_village>();
             Village village = villageRepository.Find(new Village {
                 name = contract.village_name
             }).FirstOrDefault();
             if (village != null)
             {
                 contract.village_id = village.id;
             }
             else
             {
                 village = villageRepository.Save(new Village {
                     name = contract.village_name
                 });
                 if (village != null)
                 {
                     contract.village_id = village.id;
                 }
             }
         }
     }
     return(contract);
 }