Пример #1
0
 public CityEntity Create(UserEntity UserEntity, CityEntity CityEntity)
 {
     using (var transaction = CinemasEntities.Database.BeginTransaction())
     {
         try
         {
             City City = new City();
             City = CityEntity.ToModel(City);
             CinemasEntities.Cities.Add(City);
             CinemasEntities.SaveChanges();
             CityEntity.Id = City.Id;
             transaction.Commit();
             return(CityEntity);
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw new BadRequestException("Không tạo được City mới");
         }
     }
     return(null);
 }
Пример #2
0
 public CityEntity Update(UserEntity UserEntity, int CityId, CityEntity CityEntity)
 {
     using (var transaction = CinemasEntities.Database.BeginTransaction())
     {
         try
         {
             City City = CinemasEntities.Cities.Where(c => c.Id.Equals(CityId)).FirstOrDefault();
             if (City == null)
             {
                 throw new BadRequestException("Không tìm thấy City có Id là " + CityId);
             }
             City = CityEntity.ToModel(City);
             CinemasEntities.SaveChanges();
             transaction.Commit();
             return(CityEntity);
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw new BadRequestException("Không cập nhật được City");
         }
     }
 }
Пример #3
0
 public CityEntity Update([FromUri] int CityId, [FromBody] CityEntity CityEntity)
 {
     return(CityService.Update(UserEntity, CityId, CityEntity));
 }
Пример #4
0
 public CityEntity Create([FromBody] CityEntity CityEntity)
 {
     return(CityService.Create(UserEntity, CityEntity));
 }