public bool DeleteCity(Entities.City city)
        {
            bool isCityDeleted = false;

            DbCommand dbCommand = null;

            try
            {
                using (dbCommand = database.GetStoredProcCommand(DBStoredProcedure.DeleteCity))
                {
                    database.AddInParameter(dbCommand, "@city_id", DbType.Int32, city.CityId);
                    database.AddInParameter(dbCommand, "@deleted_by", DbType.Int32, city.DeletedBy);
                    database.AddInParameter(dbCommand, "@deleted_by_ip", DbType.String, city.DeletedByIP);

                    database.AddOutParameter(dbCommand, "@return_value", DbType.Int32, 0);

                    var result = database.ExecuteNonQuery(dbCommand);

                    if (database.GetParameterValue(dbCommand, "@return_value") != DBNull.Value)
                    {
                        isCityDeleted = Convert.ToBoolean(database.GetParameterValue(dbCommand, "@return_value"));
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                dbCommand = null;
            }

            return(isCityDeleted);
        }
Exemple #2
0
        private async Task ExecuteItemSelected(Entities.City model)
        {
            try
            {
                if (IsLoading)
                {
                    return;
                }
                IsLoading   = true;
                CurrentCity = model;
                ApplicationManager <Entities.City> .AddOrUpdate("city", model);

                await NavigationService.PopAsync();
            }
            catch (Exception ex)
            {
                ExceptionService.TrackError(ex);
                await MessageService.ShowAsync(ex);
            }
            finally
            {
                IsLoading   = false;
                IsPresented = false;
            }
        }
        public IActionResult GetCity(int id, bool includePointsOfInterest = false)
        {
            Entities.City city = _cityInfoRepository.GetCity(id, includePointsOfInterest);

            if (city == null)
            {
                return(NotFound());
            }

            if (includePointsOfInterest)
            {
                var cityResult = Mapper.Map <CityDto>(city);
                return(Ok(cityResult));
                // Zonder Automapper..
                //var cityResult = new CityDto()
                //{
                //    Id = city.Id,
                //    Name = city.Name,
                //    Description = city.Description
                //};

                //foreach (var poi in city.PointsOfInterest)
                //{
                //    cityResult.PointsOfInterest.Add(
                //        new PointOfInterestDto()
                //        {
                //            Id = poi.Id,
                //            Name = poi.Name,
                //            Description = poi.Description
                //        });
                //}
                // return Ok(cityResult);
            }

            //Zonder AutoMapper
            //var cityWithoutPointsOfInterestResult =
            //    new CityWithoutPointsOfInterestDto()
            //    {
            //        Id = city.Id,
            //        Description = city.Description,
            //        Name = city.Name
            //    };
            var cityWithoutPointsOfInterestResult = Mapper.Map <CityWithoutPointsOfInterestDto>(city);

            return(Ok(cityWithoutPointsOfInterestResult));

            //var cityToReturn = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == id);
            //if (cityToReturn == null)
            //{
            //    return NotFound();
            //}

            //return Ok(cityToReturn);
        }
Exemple #4
0
        //
        // GET: /SysAdmin/City/Edit/5
        public ActionResult Edit(int id)
        {
            CityVM  viewModel = new CityVM();
            CityBAL balObject = new CityBAL();
            IQueryable <Entities.City> entites = balObject.FindBy(a => a.CityId == id);

            if (entites != null && entites.Count() > 0)
            {
                Entities.City entity = entites.FirstOrDefault();
                viewModel.CityId       = entity.CityId;
                viewModel.CityName     = entity.CityName;
                viewModel.DistrictId   = entity.DistrictId;
                viewModel.DistrictName = entity.DistrictName;
                viewModel.Status       = entity.Status;
                viewModel.Remark       = entity.Remark;
            }
            return(View(viewModel));
        }
Exemple #5
0
        public ActionResult Create(CityVM viewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    Entities.City entity = new Entities.City();
                    entity.CityId     = viewModel.CityId;
                    entity.DistrictId = viewModel.DistrictId;
                    entity.CityName   = viewModel.CityName;
                    entity.Status     = viewModel.Status;
                    entity.Remark     = viewModel.Remark;

                    CityBAL balObject = new CityBAL();
                    balObject.Add(entity);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    DistrictBAL destrictBAL = new DistrictBAL();
                    viewModel.Districts = from obj in destrictBAL.GetAll() select new SelectListItem()
                    {
                        Text = obj.DistrictName, Value = obj.DistrictId.ToString()
                    };

                    return(View(viewModel));
                }
            }
            catch
            {
                DistrictBAL destrictBAL = new DistrictBAL();
                viewModel.Districts = from obj in destrictBAL.GetAll() select new SelectListItem()
                {
                    Text = obj.DistrictName, Value = obj.DistrictId.ToString()
                };

                return(View(viewModel));
            }
        }
        public List <Entities.City> GetCitiesByState(Int32 stateId)
        {
            var cities = new List <Entities.City>();

            DbCommand dbCommand = null;

            try
            {
                using (dbCommand = database.GetStoredProcCommand(DBStoredProcedure.GetListofCitiesByState))
                {
                    database.AddInParameter(dbCommand, "@state_id", DbType.Int32, stateId);

                    using (IDataReader reader = database.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            var city = new Entities.City
                            {
                                CityId   = DRE.GetNullableInt32(reader, "city_id", 0),
                                CityName = DRE.GetNullableString(reader, "city_name", null),
                                SrNo     = DRE.GetNullableInt64(reader, "sr_no", null)
                            };

                            cities.Add(city);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbCommand = null;
            }

            return(cities);
        }
        public Int32 AddCity(Entities.City city)
        {
            var cityId = 0;

            DbCommand dbCommand = null;

            try
            {
                using (dbCommand = database.GetStoredProcCommand(DBStoredProcedure.InsertCity))
                {
                    database.AddInParameter(dbCommand, "@city_id", DbType.Int32, city.CityId);
                    database.AddInParameter(dbCommand, "@state_id", DbType.Int32, city.StateId);
                    database.AddInParameter(dbCommand, "@city_name", DbType.String, city.CityName);
                    database.AddInParameter(dbCommand, "@created_by", DbType.Int32, city.CreatedBy);
                    database.AddInParameter(dbCommand, "@created_by_ip", DbType.String, city.CreatedByIP);

                    database.AddOutParameter(dbCommand, "@return_value", DbType.Int32, 0);

                    cityId = database.ExecuteNonQuery(dbCommand);

                    if (database.GetParameterValue(dbCommand, "@return_value") != DBNull.Value)
                    {
                        cityId = Convert.ToInt32(database.GetParameterValue(dbCommand, "@return_value"));
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                dbCommand = null;
            }

            return(cityId);
        }
        public Int32 SaveCity(Entities.City city)
        {
            var cityId = 0;

            if (city.CityId == null || city.CityId == 0)
            {
                var result = IsCityNameExists((int)city.StateId, city.CityName);

                if (result == false)
                {
                    cityId = AddCity(city);
                }
                else
                {
                    cityId = -1;
                }
            }
            else if (city.IsDeleted == true)
            {
                var result = DeleteCity(city);

                if (result == true)
                {
                    cityId = 1;
                }
                else
                {
                    cityId = 0;
                }
            }
            else if (city.ModifiedBy > 0 || city.ModifiedBy != null)
            {
                cityId = UpdateCity(city);
            }

            return(cityId);
        }
 public Int32 SaveCity(Entities.City city)
 {
     return(_city.SaveCity(city));
 }
 public Int32 UpdateCity(Entities.City city)
 {
     return(_city.UpdateCity(city));
 }
 public bool DeleteCity(Entities.City city)
 {
     return(_city.DeleteCity(city));
 }
Exemple #12
0
 public Int32 AddCity(Entities.City city)
 {
     return(_city.AddCity(city));
 }