예제 #1
0
        public ResponseModel <RestaurantChefDto> Save(RestaurantChefDto dto)
        {
            ResponseModel <RestaurantChefDto> result = new ResponseModel <RestaurantChefDto>();

            using (var trans = _unitOfWork.BeginTransaction())
            {
                try
                {
                    RestaurantChef entity  = new RestaurantChef();
                    string[]       exclude = new string[] { "MenuItems", "OfferItems", "CreatedDate", "UpdatedDate", "CreatedById", "UpdatedById", "ChefCuisines" };
                    Mapper <RestaurantChefDto, RestaurantChef> .Map(dto, entity, exclude);

                    if (dto.Id > 0)
                    {
                        entity = _unitOfWork.Repository <RestaurantChef>().Get(m => m.Id == dto.Id);
                        Mapper <RestaurantChefDto, RestaurantChef> .Map(dto, entity, exclude);

                        _unitOfWork.Repository <RestaurantChef>().Update(entity);

                        result.SuccessCode = CommonConstants.SuccessCode.ChefUpdated;
                    }
                    else
                    {
                        _unitOfWork.Repository <RestaurantChef>().Insert(entity);
                        result.SuccessCode = CommonConstants.SuccessCode.ChefSaved;
                    }
                    _unitOfWork.Save();
                    dto.Id = entity.Id;
                    if (dto.ChefCuisines != null && dto.ChefCuisines.Count > 0)
                    {
                        List <ChefCuisine> offerItems = new List <ChefCuisine>();
                        foreach (var item in dto.ChefCuisines)
                        {
                            item.RestaurantChefId = dto.Id;
                        }
                        SaveChefCuisines(dto.ChefCuisines);
                    }

                    result.IsSuccess = true;
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    result.IsFailed  = true;
                    result.ErrorCode = CommonConstants.ErrorCode.InternalServerError;
                }
            }
            return(result);
        }
예제 #2
0
        public ResponseModel <PageResultModel <RestaurantChefDto> > GetChefs(PageConfiguration configuration)
        {
            ResponseModel <PageResultModel <RestaurantChefDto> > result = new ResponseModel <PageResultModel <RestaurantChefDto> >();
            PageResultModel <RestaurantChefDto> chefs = new PageResultModel <RestaurantChefDto>();

            try
            {
                Func <RestaurantChef, bool> expression = m => (configuration.ShowDeleted ? (m.IsDeleted || !m.IsDeleted) : !m.IsDeleted);
                string[] include        = new string[] { "Restaurant" };
                string[] excludeMapping = new string[] { "RestaurantChefs", "ChefCuisines" };
                if (!string.IsNullOrEmpty(configuration.Search))
                {
                    DateTime searchDate = new DateTime();
                    DateTime.TryParse(configuration.Search, out searchDate);
                    if (searchDate != new DateTime())
                    {
                        expression = m => (configuration.ShowDeleted ? (m.IsDeleted || !m.IsDeleted) : !m.IsDeleted) &&
                                     ((m.FirstName + " " + m.LastName).Contains(configuration.Search));
                    }
                    else
                    {
                        expression = m => (configuration.ShowDeleted ? (m.IsDeleted || !m.IsDeleted) : !m.IsDeleted) &&
                                     ((m.FirstName + " " + m.LastName).Contains(configuration.Search) || m.Restaurant.RestaurantName.Contains(configuration.Search));
                    }
                }
                var records = _unitOfWork.Repository <RestaurantChef>().GetMultiple(configuration, expression, include);
                foreach (var item in records.Records)
                {
                    RestaurantChefDto dto = new RestaurantChefDto();
                    dto = Mapper <RestaurantChef, RestaurantChefDto> .Map(item, dto, excludeMapping);

                    chefs.Records.Add(dto);
                }
                chefs.TotalPages      = records.TotalPages;
                chefs.TotalRecords    = records.TotalRecords;
                chefs.PageNumber      = records.PageNumber;
                chefs.Showing         = records.Showing;
                result.IsSuccess      = true;
                result.ResponseObject = chefs;
            }
            catch (Exception ex)
            {
                result.IsFailed  = true;
                result.ErrorCode = CommonConstants.ErrorCode.InternalServerError;
            }
            return(result);
        }
        public async Task <IActionResult> Save(RestaurantChefDto dto)
        {
            var result = new ResponseModel <RestaurantChefDto>();

            if (!ModelState.IsValid)
            {
                result.IsFailed  = true;
                result.ErrorCode = CommonConstants.ErrorCode.InvalidModel;
            }
            else
            {
                result = _service.Save(dto);
            }
            result = MessageHelper <RestaurantChefDto> .GetResponse(result);

            return(Ok(result));
        }