Esempio n. 1
0
        public async Task <bool> CreateContract(RestaurantContractServiceModel serviceModel)
        {
            RestaurantContract restaurantContract = AutoMapper.Mapper.Map <RestaurantContract>(serviceModel);
            Restaurant         restaurant         = await GetRestaurantById(restaurantContract.Id);

            restaurant.IsContractActive = true;

            var isContractExsited = await this.context.RestaurantContracts
                                    .AnyAsync(ress => ress.Id == restaurantContract.Id);

            int result = int.MinValue;

            if (isContractExsited)
            {
                await Task.Run(() => this.context.RestaurantContracts.Update(restaurantContract));

                result = await this.context.SaveChangesAsync();

                return(result > num);
            }

            await this.context.RestaurantContracts.AddAsync(restaurantContract);

            result = await this.context.SaveChangesAsync();

            return(result > num);
        }
Esempio n. 2
0
 public static Restaurant ToEntity(this RestaurantContract restaurant)
 {
     return(new Restaurant
     {
         Id = restaurant.Id,
         Name = restaurant.Name,
         ImageUrl = restaurant.ImageUrl
     });
 }
 public IHttpActionResult Post(RestaurantContract restaurantContract)
 {
     return(_restaurantHandler.Post(restaurantContract) ? (IHttpActionResult)Ok() : BadRequest());
 }
 public bool Post(RestaurantContract restaurantContract)
 {
     return(_uow.RestaurantRepository.CreateOrUpdate(restaurantContract.ToEntity()));
 }