예제 #1
0
 public CityModel SaveCity(CityModel model)
 {
     //unitOfWork.StartTransaction();
     CityRepository repo = new CityRepository(unitOfWork);
     City city = new City();
     AutoMapper.Mapper.Map(model, city);
     repo.Insert(city);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(city, model);
     return model;
 }
예제 #2
0
 public CityModel GetCityById(int cityId)
 {
     //unitOfWork.StartTransaction();
     CityRepository repo = new CityRepository(unitOfWork);
     CityModel cityModel = new CityModel();
     City city = new City();
     AutoMapper.Mapper.Map(cityModel, city);
     city = repo.GetAll().Where(x => x.CityId == cityId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(city, cityModel);
     return cityModel;
 }
예제 #3
0
 public CityModel UpadteCity(CityModel model)
 {
     //unitOfWork.StartTransaction();
     CityRepository repo = new CityRepository(unitOfWork);
     City city = new City();
     city = repo.GetAll().Where(x => x.CityId == model.CityId).FirstOrDefault();
     AutoMapper.Mapper.Map(model, city);
     repo.Update(city);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(city, model);
     return model;
 }
예제 #4
0
        public IHttpActionResult PostCity(CityBindingModel model)
        {
            try {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }
                CityModel cityModel = new CityModel();
                AutoMapper.Mapper.Map(model, cityModel);
                cityModel = cityService.SaveCity(cityModel);
                AutoMapper.Mapper.Map(cityModel, model);
                return Ok(model);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
        }
예제 #5
0
 public IHttpActionResult PutCity(CityBindingModel model)
 {
     try {
         if (!ModelState.IsValid)
         {
             return BadRequest(ModelState);
         }
         CityModel cityModel = new CityModel();
         AutoMapper.Mapper.Map(model, cityModel);
         cityModel = cityService.UpadteCity(cityModel);
         AutoMapper.Mapper.Map(cityModel, model);
         return Ok(model);
     }
     catch(Exception ex)
     {
         return BadRequest(ex.Message);
     }
 }