public ActionResult Create(DayModeCreateRequest request)
        {
            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion

                dayModeService.CreateDayMode(request);
                response = BaseResponse <dynamic> .Get(true, ConstantManager.CreateSuccess(""), null, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Day Mode : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
Exemple #2
0
        public void CreateDayMode(DayModeCreateRequest request)
        {
            request.BrandId = 1;
            var dayFilter = 0;

            request.Active = true;
            foreach (var item in request.DaysOfTheWeek)
            {
                dayFilter += (int)Math.Pow(2, item);
            }
            var entity = Mapper.Map <DayModeCreateRequest, DayMode>(request);

            entity.DayFilter = dayFilter;
            Create(entity);
        }