public async Task <ActionResult> Login(UserLoginRequest 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 var data = await userService.Login(brandToken, request); response = BaseResponse <dynamic> .Get(true, ConstantManager.Success("Login"), data, 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("Login : ") + e.ToString(), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); }
public BaseResponse <List <RatingAPIViewModel> > GetRatingByOrderId(int orderId) { try { var service = this.Service <IRatingService>(); var list = service.GetRatingByOrderId(orderId); if (list == null) { throw ApiException.Get(true, ConstantManager.MES_RATINGPRODUCT_NOTFOUNT, ResultEnum.RatingProductNotFound, HttpStatusCode.OK); } return(BaseResponse <List <RatingAPIViewModel> > .Get(true, ConstantManager.MES_RATINGPRODUCT_OK, list, ResultEnum.Success)); } catch (Exception ex) { if (ex is ApiException) { throw ex; } else { throw ApiException.Get(false, ex.ToString(), ResultEnum.InternalError, HttpStatusCode.InternalServerError); } } throw new NotImplementedException(); }
public ActionResult Get() { 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 var data = shiftRegisterService.Get(); var groupby = data.GroupBy(p => p.EmpName, p => p, (key, shift) => new { Name = key, Shift = shift.ToList() }); response = BaseResponse <dynamic> .Get(false, ConstantManager.SUCCESS, groupby, 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("Shift Register : ") + e.ToString(), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); }
public ActionResult Add(List <ShiftRegisterBasic> 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 shiftRegisterService.RegistShift(request); response = BaseResponse <dynamic> .Get(false, ConstantManager.CreateSuccess("Shift Register :"), 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("Shift Register : ") + e.ToString(), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); }
public ActionResult Register(UserBasic 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 var task = userService.Register(brandToken, request); task.Wait(); response = BaseResponse <dynamic> .Get(true, ConstantManager.Success("Register"), 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("Register : ") + e.ToString(), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); // create asp user , employee , membership , account }
public ActionResult <List <DayModeBasic> > Get() { 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 var data = dayModeService.Get(); response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, data, 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); }
public HttpResponseMessage GetProvince() { HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; BaseResponse <List <ProvinceAPIViewModel> > response = new BaseResponse <List <ProvinceAPIViewModel> >(); try { ProvinceDomain provinceDomain = new ProvinceDomain(); response = provinceDomain.GetProvince(); } catch (ApiException e) { httpResponseMessage.StatusCode = e.StatusCode; response = BaseResponse <List <ProvinceAPIViewModel> > .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <List <ProvinceAPIViewModel> > .Get(false, ex.ToString(), null, ResultEnum.InternalError); throw; } httpResponseMessage.Content = new JsonContent(response); return(httpResponseMessage); }
public HttpResponseMessage GetListCategoryExtra(int catId, int storeId) { CategoryExtraMappingDomain categoryExtraMappingDomain = new CategoryExtraMappingDomain(); ProductCategoryDomain categoryDomain = new ProductCategoryDomain(); ProductCategoryAPIViewModel Cat = new ProductCategoryAPIViewModel(); HttpResponseMessage responseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; BaseResponse <ProductCategoryAPIViewModel> response = new BaseResponse <ProductCategoryAPIViewModel>(); try { // get Extra mapping by PrimaryCategoryId var extra = categoryExtraMappingDomain.GetCategoryExtraMapping(catId, storeId); // get Category by ExtraCategoryId response = categoryDomain.GetCategoryByExtraId(extra.Data.ExtraCategoryId, storeId); } catch (ApiException e) { responseMessage.StatusCode = e.StatusCode; response = BaseResponse <ProductCategoryAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <ProductCategoryAPIViewModel> .Get(false, "ProductCategoryError : " + ex.ToString(), null, ResultEnum.InternalError); } responseMessage.Content = new JsonContent(response); return(responseMessage); }
public HttpResponseMessage GetProductCategoriesByStoreId(CategoryRequest <string> request) { List <ProductCategoryAPIViewModel> productCategories = new List <ProductCategoryAPIViewModel>(); HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; BaseResponse <List <ProductCategoryAPIViewModel> > response = new BaseResponse <List <ProductCategoryAPIViewModel> >(); try { ProductCategoryDomain domain = new ProductCategoryDomain(); response = domain.GetProductCategoriesByRequest(request); } catch (ApiException e) { httpResponseMessage.StatusCode = e.StatusCode; response = BaseResponse <List <ProductCategoryAPIViewModel> > .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <List <ProductCategoryAPIViewModel> > .Get(false, "ProductCategoryException: " + ex.ToString(), null, ResultEnum.InternalError); } httpResponseMessage.Content = new JsonContent(response); return(httpResponseMessage); }
public BaseResponse <List <ProductCategoryAPIViewModel> > GetProductCategoriesByRequest(CategoryRequest <string> request) { var categoryService = this.Service <IProductCategoryService>(); try { if (request.StoreId == null) { throw ApiException.Get(false, "StoreId is required!", ResultEnum.StoreIdNotFound, HttpStatusCode.BadRequest); } var cateVM = categoryService.GetProductCategoriesByRequest(request); if (cateVM == null) { throw ApiException.Get(true, ConstantManager.MES_PRODUCTCATEGORY_NOT_FOUND, ResultEnum.ProductCategoryNotFound, HttpStatusCode.OK); } return(BaseResponse <List <ProductCategoryAPIViewModel> > .Get(true, ConstantManager.MES_SUCCESS, cateVM, ResultEnum.Success)); } catch (Exception ex) { if (ex is ApiException) { throw ex; } throw ApiException.Get(false, ex.ToString(), ResultEnum.InternalError, HttpStatusCode.InternalServerError); } }
public HttpResponseMessage UpdateTableCode(OrderAPIViewModel order) { var customerDomain = new CustomerDomain(); BaseResponse <OrderHistoryAPIViewModel> response = new BaseResponse <OrderHistoryAPIViewModel>(); HttpResponseMessage httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; var customerId = customerDomain.getCustomerIdFromToken(RequestContext); if (customerId != null) { order.CustomerID = customerId; } var domain = new OrderDomain(); try { response = domain.UpdateTableCode(order, customerId.Value); } catch (ApiException e) { httpResponseMessage.StatusCode = e.StatusCode; response = BaseResponse <OrderHistoryAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <OrderHistoryAPIViewModel> .Get(false, e.ToString(), null, ResultEnum.InternalError); } httpResponseMessage.Content = new JsonContent(response); return(httpResponseMessage); }
private BaseResponse <bool> CheckGeneralPromotionRule(Promotion promotion, OrderAPIViewModel order) { if (order.BrandId != promotion.BrandId) { throw ApiException.Get(false, "Khuyến mãi không dành cho hãng này", ResultEnum.PromotionNotApplyToBrand, HttpStatusCode.BadRequest); } var now = DateTime.Now; if ((promotion.FromDate != null && now < promotion.FromDate) && (promotion.ToDate != null && now > promotion.ToDate)) { throw ApiException.Get(false, "Ngày áp dụng không hợp lệ", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } if ((promotion.ApplyFromTime != null && now.Hour < promotion.ApplyFromTime) && (promotion.ApplyToTime != null && now.Hour > promotion.ApplyToTime)) { throw ApiException.Get(false, "Thời gian áp dụng không hợp lệ", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } var sMappingService = Service <IPromotionStoreMappingService>(); if (order.StoreID == null) { throw ApiException.Get(false, "Thiếu thông tin cửa hàng", ResultEnum.LackOfInformation, HttpStatusCode.BadRequest); } var mappings = sMappingService.GetActive(m => m.PromotionId == promotion.PromotionID) .Select(m => m.StoreId).AsEnumerable(); if (!mappings.Contains(order.StoreID.Value)) { throw ApiException.Get(false, "Khuyến mãi không áp dụng cho cửa hàng này", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } return(BaseResponse <bool> .Get(true, "Hợp lệ", true, ResultEnum.Success, null)); }
public ActionResult Accept(AttentdenceAcceptRequest 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 attendanceService.Accept(request); response = BaseResponse <dynamic> .Get(true, ConstantManager.CreateSuccess("Attendance :"), 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("Attendance : ") + e.ToString(), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); }
public ActionResult <List <PayrollPeriodResponse> > Get([FromQuery] int?empId) { 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 var data = payrollperiodService.Get(empId); if (data.Count <= 0) { throw ApiException.Get(true, ConstantManager.NotFound(" Payroll Period "), ResultEnum.PeriodNotFound, HttpStatusCode.NotFound); } response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, data, 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(e.ToString()), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); }
public ActionResult Create([FromBody] PayrollPeriodBasic 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 payrollperiodService.CreatePeriod(request); response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, 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(e.ToString()), null, ResultEnum.InternalError); } result = new JsonResult(response); return(result); //var a = ResponseMessage(httpResponseMessage); //return result; }
public HttpResponseMessage GetRating(RatingRequest <string> request) { HttpResponseMessage responseMessage = new HttpResponseMessage(); BaseResponse <TotalRatingAPIViewModel> response = new BaseResponse <TotalRatingAPIViewModel>(); try { var domain = new RatingDomain(); //response = domain.GetRatingByProductId(product_id); response = domain.GetRatingByRequest(request); } catch (ApiException e) { // catch ApiException responseMessage.StatusCode = e.StatusCode; response = BaseResponse <TotalRatingAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <TotalRatingAPIViewModel> .Get(false, ex.ToString(), null, ResultEnum.InternalError); } //return responseMessage.Content = new JsonContent(response); return(responseMessage); }
public HttpResponseMessage UpdateRating(RatingAPIViewModel rating) { HttpResponseMessage responseMessage = new HttpResponseMessage(); BaseResponse <RatingAPIViewModel> response = new BaseResponse <RatingAPIViewModel>(); try { var domain = new RatingDomain(); response = domain.UpdateRatingProduct(rating); } catch (ApiException e) { // catch ApiException responseMessage.StatusCode = e.StatusCode; response = BaseResponse <RatingAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <RatingAPIViewModel> .Get(false, ex.ToString(), null, ResultEnum.InternalError); } //return responseMessage.Content = new JsonContent(response); return(responseMessage); throw new NotImplementedException(); }
public HttpResponseMessage CreatProductBrand(ProductBrandAPIViewModel request) { HttpResponseMessage responseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; BaseResponse <ProductBrandAPIViewModel> response = new BaseResponse <ProductBrandAPIViewModel>(); try { // Domain var domain = new ProductBrandDomain(); response = domain.CreateProductBrand(request); } catch (ApiException e) { // catch ApiException responseMessage.StatusCode = e.StatusCode; response = BaseResponse <ProductBrandAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception ex) { responseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <ProductBrandAPIViewModel> .Get(false, ex.ToString(), null, ResultEnum.InternalError); } //return responseMessage.Content = new JsonContent(response); return(responseMessage); throw new NotImplementedException(); }
public BaseResponse <Promotion> IsPromotionValidFor(Promotion promotion, OrderAPIViewModel order, Membership membership = null) { var gCheck = CheckGeneralPromotionRule(promotion, order); var pDetails = GetPromotionDetailsByPromotion(promotion.PromotionCode); var mCheck = CheckMembership(promotion, pDetails, membership); if (promotion.ApplyLevel == (int)PromotionApplyLevelEnum.Order) { foreach (var pD in pDetails) { var pDetailCheck = IsPromotionDetailValidFor(pD, order, membership); } } else { foreach (var pD in pDetails) { var pDetailCheck = IsPromotionDetailValidFor(pD, order.OrderDetails, membership); } } return(BaseResponse <Promotion> .Get(true, "Promotion can be applied", promotion, ResultEnum.Success, null)); }
public BaseResponse <ProductBrandAPIViewModel> UpdateProductBrand(ProductBrandAPIViewModel productBrand) { var service = this.Service <IProductBrandService>(); var productBrandViewModel = service.UpdateProductBrand(productBrand); if (productBrandViewModel == null) { throw ApiException.Get(false, ConstantManager.PRODUCT_BRAND_UPDATE_FAIL, ResultEnum.ProductBrandUpdateFail, HttpStatusCode.BadRequest); } return(BaseResponse <ProductBrandAPIViewModel> .Get(true, ConstantManager.MES_UPDATE_PRODUCT_BRAND_SUCCESS, productBrandViewModel, ResultEnum.Success)); }
public BaseResponse <List <ProductBrandAPIViewModel> > GetProductBrand(ProductBrandRequest <string> request) { var service = this.Service <IProductBrandService>(); var list = service.GetProductBrand(request); if (list == null) { throw ApiException.Get(false, ConstantManager.MES_PRODUCTBRAND_NOTFOUND, ResultEnum.ProductBrandNotFound, HttpStatusCode.BadRequest); } return(BaseResponse <List <ProductBrandAPIViewModel> > .Get(true, ConstantManager.MES_PRODUCTBRAND_OK, list, ResultEnum.Success)); }
//public int CountTotalOrdersOneDay(DateTime dateTime) //{ // IOrderService orderService = DependencyUtils.Resolve<IOrderService>(); // int count = orderService.CountTotalOrderInOneDay(dateTime); // return count; //} public BaseResponse <List <OrderHistoryAPIViewModel> > GetOrderHistoryByRequest(OrderRequest <string> request) { var ser = this.Service <IOrderService>(); var list = ser.GetOrderHistoryByRequest(request); if (list.Count <= 0) { throw ApiException.Get(true, ConstantManager.MES_ORDER_HISTORY_NOTFOUND, ResultEnum.OrderHistoryNotFound, HttpStatusCode.OK); } return(BaseResponse <List <OrderHistoryAPIViewModel> > .Get(true, ConstantManager.MES_SUCCESS, list, ResultEnum.Success)); }
//[Route("{PromotionID?}")] //[HttpGet] public HttpResponseMessage GetPromotion(PromotionQueryRequest <dynamic> request) { var response = new BaseResponse <dynamic>(); var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; var customerId = claimPrincipal.Claims.Where(c => c.Type == "CustomerId").Select(c => c.Value).SingleOrDefault(); var cDomain = new CustomerDomain(); var id = Int32.Parse(customerId); var customer = cDomain.GetCustomerById(id); var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; var pDomain = new PromotionDomain(); Membership member = customer.MembershipVM.ToEntity(); request.Membership = member; var promotion = pDomain.GetPromotion(request).ToList(); if (promotion.Count == 0) { var res = BaseResponse <dynamic> .Get(false, "Không tìm thấy khuyến mãi nào", null, ResultEnum.PromotionNotFound); resp.Content = new JsonContent(res); resp.StatusCode = HttpStatusCode.NotFound; return(resp); } try { response = BaseResponse <dynamic> .Get(false, "Thành công", null, ResultEnum.Success); if (promotion.Count == 1) { response.Data = promotion.FirstOrDefault(); } else { response.Data = promotion; } } catch (ApiException e) { resp.StatusCode = e.StatusCode; response = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { response = BaseResponse <dynamic> .Get(false, e.Message, null, ResultEnum.InternalError); resp.StatusCode = HttpStatusCode.InternalServerError; } resp.Content = new JsonContent(response); return(resp); }
public HttpResponseMessage CheckVoucher(CheckVoucherViewModel request) { //Logger.Log("Store " + model.terminalId); //Logger.Log("|CheckVoucherCode| begin method"); var response = new BaseResponse <dynamic>(); var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; var customerId = claimPrincipal.Claims.Where(c => c.Type == "CustomerId").Select(c => c.Value).SingleOrDefault(); var cDomain = new CustomerDomain(); var id = Int32.Parse(customerId); var customer = cDomain.GetCustomerById(id); var oDomain = new OrderDomain(); var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; try { DateTime time = DataService.Models.Utils.GetCurrentDateTime(); var pDomain = new PromotionDomain(); var orderVM = new OrderAPIViewModel(); var voucher = pDomain.GetVoucher(request.VoucherCode); var mbs = customer.MembershipVM; orderVM.OrderDetails = request.Data; orderVM.StoreID = request.StoreId; AddInfo(orderVM, request); oDomain.CalculateOrderPrice(orderVM, time); //temp: each voucher has only 1 detail now var applyResult = pDomain.IsVoucherValidFor(voucher, orderVM, mbs); orderVM = pDomain.ApplyPromotionToOrder(orderVM, applyResult, mbs); response = BaseResponse <dynamic> .Get(true, "Thành công", orderVM, ResultEnum.Success); } catch (ApiException e) { resp.StatusCode = e.StatusCode; response = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { resp.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <dynamic> .Get(false, e.ToString(), null, ResultEnum.InternalError); } resp.Content = new JsonContent(response); return(resp); }
public HttpResponseMessage GetHistoryOrder(OrderRequest <string> request) { BaseResponse <List <OrderHistoryAPIViewModel> > response = new BaseResponse <List <OrderHistoryAPIViewModel> >(); var domain = new OrderDomain(); var customerDomain = new CustomerDomain(); HttpResponseMessage httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; var customerId = customerDomain.getCustomerIdFromToken(RequestContext); var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; var employeeId = claimPrincipal.Claims.Where(c => c.Type == "EmployeeId").Select(c => c.Value).SingleOrDefault(); var userName = claimPrincipal.Claims.Where(c => c.Type == "UserName").Select(c => c.Value).SingleOrDefault(); Int32 employeeID = 0; Int32.TryParse(employeeId, out employeeID); if (request.CreateAtMax.HasValue) { request.CreateAtMax = request.CreateAtMax.Value.GetEndOfDate(); } if (request.CreateAtMin.HasValue) { request.CreateAtMin = request.CreateAtMin.Value.GetEndOfDate(); } if (customerId != null) { request.CustomerId = customerId.Value; } if (employeeID != 0) { request.UserName = userName; } try { response = domain.GetOrderHistoryByRequest(request); } catch (ApiException e) { httpResponseMessage.StatusCode = e.StatusCode; response = BaseResponse <List <OrderHistoryAPIViewModel> > .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <List <OrderHistoryAPIViewModel> > .Get(false, e.ToString(), null, ResultEnum.InternalError); } httpResponseMessage.Content = new JsonContent(response); return(httpResponseMessage); }
public BaseResponse <Voucher> IsVoucherValidFor(Voucher voucher, OrderAPIViewModel order, Membership membership = null) { var available = IsVoucherAvailable(voucher); if (voucher.MembershipCardId != null) { if (voucher.MembershipCardId != membership.Id) { throw ApiException.Get(false, "Voucher không dành cho thành viên này", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } } var pValid = IsPromotionValidFor(voucher.Promotion, order, membership); return(BaseResponse <Voucher> .Get(true, "Voucher có thể sử dụng", voucher, ResultEnum.Success, null)); }
public BaseResponse <PromotionDetail> IsPromotionDetailValidFor(PromotionDetail pDetail, IEnumerable <OrderDetailAPIViewModel> OrderDetailAPIViewModels, Membership membership = null) { foreach (var oD in OrderDetailAPIViewModels) { if (pDetail.BuyProductCode != null && pDetail.BuyProductCode != oD.ProductCode) { throw ApiException.Get(false, "Có sản phẩm không hợp lệ", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } if (pDetail.MinBuyQuantity != null) { if (oD.Quantity < pDetail.MinBuyQuantity) { throw ApiException.Get(false, "Số lượng sản phẩm không phù hợp", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } } if (pDetail.MaxBuyQuantity != null) { if (oD.Quantity > pDetail.MaxBuyQuantity) { throw ApiException.Get(false, "Số lượng sản phẩm không phù hợp", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } } var cashbackAcc = membership.Accounts.FirstOrDefault(a => a.Type == (int)AccountTypeEnum.PointAccount); if (cashbackAcc == null) { throw ApiException.Get(false, "Không thể tìm thấy tài khoản tích điểm", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } if (pDetail.MinPoint != null) { if (cashbackAcc.Balance < pDetail.MinPoint) { throw ApiException.Get(false, "Điểm thành viên không hợp lệ", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } } if (pDetail.MaxPoint != null) { if (cashbackAcc.Balance > pDetail.MaxPoint) { throw ApiException.Get(false, "Điểm thành viên không hợp lệ", ResultEnum.VoucherNotAvailable, HttpStatusCode.BadRequest); } } } return(BaseResponse <PromotionDetail> .Get(true, "PromotionDetail can be applied", pDetail, ResultEnum.Success, null)); }
public HttpResponseMessage CreateOrder(OrderAPIViewModel order) { var customerDomain = new CustomerDomain(); BaseResponse <OrderHistoryAPIViewModel> response = new BaseResponse <OrderHistoryAPIViewModel>(); HttpResponseMessage httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; #region get CustomerId and EmployeeId from Token var customerId = customerDomain.getCustomerIdFromToken(RequestContext); if (customerId != null) { order.CustomerID = customerId; } var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; var employeeId = claimPrincipal.Claims.Where(c => c.Type == "EmployeeId").Select(c => c.Value).SingleOrDefault(); var userName = claimPrincipal.Claims.Where(c => c.Type == "UserName").Select(c => c.Value).SingleOrDefault(); Int32 employeeID = 0; Int32.TryParse(employeeId, out employeeID); if (employeeID != 0) { order.EmployeeId = employeeID; order.CheckInPerson = userName; } #endregion IOrderDomain domain = new OrderDomain(); try { response = domain.AddOrderFromMobile(order); } catch (DataService.Utilities.ApiException e) { httpResponseMessage.StatusCode = e.StatusCode; response = BaseResponse <OrderHistoryAPIViewModel> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError; response = BaseResponse <OrderHistoryAPIViewModel> .Get(false, e.ToString(), null, ResultEnum.InternalError); } httpResponseMessage.Content = new JsonContent(response); return(httpResponseMessage); }
public HttpResponseMessage GetVoucher([FromUri] VoucherQueryRequest <dynamic> request) { var response = new BaseResponse <List <VoucherAPIViewModel> >(); var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; var customerId = claimPrincipal.Claims.Where(c => c.Type == "CustomerId").Select(c => c.Value).SingleOrDefault(); var cDomain = new CustomerDomain(); var id = Int32.Parse(customerId); var customer = cDomain.GetCustomerById(id); var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; var pDomain = new PromotionDomain(); Membership member = customer.MembershipVM.ToEntity(); request.MembershipVM = member; request.BrandId = customer.BrandId; //if (voucher.Count == 0) //{ // var res = BaseResponse<dynamic>.Get(false, "Không tìm thấy voucher nào", null, ResultEnum.VoucherNotFound); // resp.Content = new JsonContent(res); // resp.StatusCode = HttpStatusCode.NotFound; // return resp; //} try { var voucher = pDomain.GetVoucher(request).ToList(); response = BaseResponse <List <VoucherAPIViewModel> > .Get(false, "Thành công", voucher, ResultEnum.Success); } catch (ApiException e) { resp.StatusCode = e.StatusCode; response = BaseResponse <List <VoucherAPIViewModel> > .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { response = BaseResponse <List <VoucherAPIViewModel> > .Get(false, e.Message, null, ResultEnum.InternalError); resp.StatusCode = HttpStatusCode.InternalServerError; } resp.Content = new JsonContent(response); return(resp); }
public BaseResponse <string> DeleteDelivery(int deliveryId, int customerId) { if (customerId == 0) { throw ApiException.Get(false, ConstantManager.MES_DELETE_DELIVERY_FAIL, ResultEnum.CustomerIdInTokenWrong, HttpStatusCode.NotFound); } var deliService = this.Service <IDeliveryInfoService>(); var deliveryInfoOld = deliService.GetDeliveriesByCustomerId(customerId); var deli = deliveryInfoOld.Where(p => p.Id == deliveryId).FirstOrDefault(); if (deli == null) { throw ApiException.Get(false, ConstantManager.MES_DELIVERYID_WRONG, ResultEnum.DeleteFail, HttpStatusCode.NotFound); } else { deliService.DeleteDelivery(deli); return(BaseResponse <string> .Get(true, ConstantManager.MES_DELETE_DELIVERY_SUCCESS, null, ResultEnum.Success)); } }