예제 #1
0
        public object GetById(long Id, bool isdetailsview)
        {
            if (!isdetailsview)
            {
                var      model    = this._dbContext.Citys.Where(s => s.Id == Id).FirstOrDefault();
                CitysDTO modelDTO = Mapper.Map <Citys, CitysDTO>(model);
                return(modelDTO);
            }
            else
            {
                var model = this._dbContext.Citys.Where(s => s.Id == Id).FirstOrDefault();
                Dictionary <string, object> details = new Dictionary <string, object>();
                string stateName = " - ", districtName = " - ", talukaName = " - ";

                if (model.StateId.HasValue)
                {
                    stateName = this._dbContext.Citys.Where(s => s.Id == model.StateId.Value).FirstOrDefault()?.CityName;
                }
                if (model.DistrictId.HasValue)
                {
                    districtName = this._dbContext.Citys.Where(s => s.Id == model.DistrictId.Value).FirstOrDefault()?.CityName;
                }
                if (model.TalukaId.HasValue)
                {
                    talukaName = this._dbContext.Citys.Where(s => s.Id == model.TalukaId.Value).FirstOrDefault()?.CityName;
                }

                details.Add("City", model.CityName);

                details.Add("City Type", Converters.GetCityTypeFromId(model.CityType));
                details.Add("State", stateName);

                details.Add("District", districtName);
                details.Add("Taluka", talukaName);

                details.Add("PinCode", model.PinCode);

                details.Add("Latitude", model.Latitude);
                details.Add("Longitude", model.Longitude);

                details.Add("Male Population", model.MPopulation);
                details.Add("Female Population", model.FPopulation);

                details.Add("Created Date", model.CreatedDate);
                details.Add("Updated Date", model.UpdatedDate);

                details.Add("Active", model.IsActive);
                details.Add("Deleted", model.IsDeleted);

                return(details);
            }
        }
예제 #2
0
 public object Post([FromBody] CitysDTO model)
 {
     try
     {
         var data = _ICitysRepository.SaveUpdate(model);
         _response.Result = data;
     }
     catch (Exception ex)
     {
         _response.IsSuccess     = false;
         _response.ErrorMessages = new List <ErrorMessageDTO>()
         {
             new ErrorMessageDTO()
             {
                 Message = ex.ToString()
             }
         };
     }
     return(_response);
 }
예제 #3
0
        public object SaveUpdate(CitysDTO modelDTO)
        {
            modelDTO.UpdatedDate = Converters.GetCurrentEpochTime();
            Citys model = Mapper.Map <CitysDTO, Citys>(modelDTO);

            if (model.Id == 0)
            {
                model.CreatedDate = modelDTO.UpdatedDate;
                model.IsActive    = true;
                model.IsDeleted   = false;
                this._dbContext.Citys.Add(model);
                this._dbContext.SaveChanges();
            }
            else
            {
                this._dbContext.Entry(model).State = EntityState.Modified;
                this._dbContext.SaveChanges();
            }
            modelDTO = Mapper.Map <Citys, CitysDTO>(model);
            return(model);
        }