Exemple #1
0
 public LogicResult <ProductCartModel> GetProductDetailForAddToCart(Guid productId)
 {
     try
     {
         var model = (from product in _productQueryService.GetAll()
                      join productType in _productTypeServiceFacade.Data on product.TypeId equals productType.Id
                      where product.Id == productId
                      select new ProductCartModel {
             Id = product.Id, Name = product.Name, Type = productType.Type, Point = productType.Point, UserId = CurrentUser.Id
         }).FirstOrDefault();
         var priceDetail = new PriceDetail
         {
             Type = model.Type.ToEnum <ProductType>()
         };
         var paymentDetailResult = _priceCalculationService.CalculatePrice(priceDetail);
         if (paymentDetailResult.IsSucceed)
         {
             model.PaymentDetail = paymentDetailResult.Data;
             return(LogicResult <ProductCartModel> .Succeed(model));
         }
         else
         {
             return(LogicResult <ProductCartModel> .Failure(Validation.UnSuccessfullOperation));
         }
     }
     catch
     {
         return(LogicResult <ProductCartModel> .Failure(Validation.UnSuccessfullOperation));
     }
 }
        public LogicResult <MemoryStream> GenerateInvoicePdf(ProductInvoiceModel invoice)
        {
            try
            {
                MemoryStream workStream = new MemoryStream();

                Document doc = new Document();
                doc.SetMargins(0f, 0f, 0f, 0f);
                //Create PDF Table with 5 columns
                PdfPTable tableLayout = new PdfPTable(8);
                doc.SetMargins(0f, 0f, 0f, 0f);
                //Create PDF Table

                PdfWriter.GetInstance(doc, workStream).CloseStream = false;
                doc.Open();

                //Add Content to PDF
                doc.Add(AddContentToPDF(tableLayout, invoice));

                // Closing the document
                doc.Close();

                byte[] byteInfo = workStream.ToArray();
                workStream.Write(byteInfo, 0, byteInfo.Length);
                workStream.Position = 0;
                return(LogicResult <MemoryStream> .Succeed(workStream));
            }
            catch
            {
                return(LogicResult <MemoryStream> .Failure(Validation.UnSuccessfullOperation));
            }
        }
 public LogicResult <ProductInvoiceModel> GetInvoiceForDownload(Guid productId, Guid userId)
 {
     try
     {
         var invoice = (from userToProduct in _userToProductQueryService.GetAll()
                        join product in _productQueryService.GetAll() on userToProduct.ProductId equals product.Id
                        join productType in _productTypeServiceFacade.Data on product.TypeId equals productType.Id
                        where userToProduct.UserId == userId && userToProduct.ProductId == productId
                        select new ProductInvoiceModel
         {
             Day = userToProduct.Day,
             UserId = userToProduct.UserId,
             Point = userToProduct.Point,
             Id = userToProduct.ProductId,
             PaymentDetail = SerializerHelper.DeserializeObject <PaymentDetail>(userToProduct.PaymentDetail),
             Name = product.Name,
             Type = productType.Type
         }).FirstOrDefault();
         return(LogicResult <ProductInvoiceModel> .Succeed(invoice));
     }
     catch
     {
         return(LogicResult <ProductInvoiceModel> .Failure(Validation.UnSuccessfullOperation));
     }
 }
Exemple #4
0
 public LogicResult Save(ProductInvoiceModel model)
 {
     try
     {
         var dto = new UserToProductDTO
         {
             Amount        = model.PaymentDetail.TotalPrice,
             UserId        = CurrentUser.Id,
             PaymentDetail = SerializerHelper.Serialize(model.PaymentDetail),
             Day           = model.Day,
             ProductId     = model.Id,
             Point         = model.Point,
         };
         var result = _userToProductService.Save(dto);
         if (result.IsSucceed)
         {
             var product = Store.CartProducts.FirstOrDefault(m => m.Id == model.Id);
             Store.CartProducts.Remove(product);
             return(LogicResult.Succeed());
         }
         else
         {
             return(LogicResult.Failure(Validation.UnSuccessfullOperation));
         }
     }
     catch
     {
         return(LogicResult <int> .Failure(Validation.UnSuccessfullOperation));
     }
 }
Exemple #5
0
        public LogicResult <int> AddToCart(ProductCartModel model)
        {
            if (Store.CartProducts.Any(m => m.Id == model.Id && m.UserId == model.UserId))
            {
                return(LogicResult <int> .Failure(Validation.PrductExistInCart));
            }
            if (model.Day <= 0)
            {
                return(LogicResult <int> .Failure(Validation.MustBeHigherThanZero));
            }
            var priceDetail = new PriceDetail
            {
                Day  = model.Day,
                Type = model.Type.ToEnum <ProductType>()
            };
            var paymentDetailResult = _priceCalculationService.CalculatePrice(priceDetail);

            if (paymentDetailResult.IsSucceed)
            {
                model.PaymentDetail = paymentDetailResult.Data;
                Store.CartProducts.Add(model);
                return(LogicResult <int> .Succeed(DataCount));
            }
            else
            {
                return(LogicResult <int> .Failure(Validation.UnSuccessfullOperation));
            }
        }
Exemple #6
0
 public LogicResult <IEnumerable <ProductCartModel> > GetProducts()
 {
     try
     {
         return(LogicResult <IEnumerable <ProductCartModel> > .Succeed(Store.CartProducts.Where(m => m.UserId == CurrentUser.Id)));
     }
     catch
     {
         return(LogicResult <IEnumerable <ProductCartModel> > .Failure(Validation.UnSuccessfullOperation));
     }
 }
 public LogicResult <ProductDTO> Save(ProductDTO entity)
 {
     try
     {
         var dto = _productBusinessLogic.Save(entity);
         return(LogicResult <ProductDTO> .Succeed(entity));
     }
     catch (Exception exception)
     {
         return(LogicResult <ProductDTO> .Failure(exception));
     }
 }
 public LogicResult <IEnumerable <ProductDTO> > GetAll()
 {
     try
     {
         var products = _productBusinessLogic.GetAll();
         return(LogicResult <IEnumerable <ProductDTO> > .Succeed(products));
     }
     catch (Exception exception)
     {
         return(LogicResult <IEnumerable <ProductDTO> > .Failure(exception));
     }
 }
 public LogicResult <PaymentTypeDTO> Save(PaymentTypeDTO entity)
 {
     try
     {
         var dto = _paymentTypeBusinessLogic.Save(entity);
         return(LogicResult <PaymentTypeDTO> .Succeed(dto));
     }
     catch (Exception exception)
     {
         return(LogicResult <PaymentTypeDTO> .Failure(exception));
     }
 }
 public LogicResult <UserDTO> Save(UserDTO entity)
 {
     try
     {
         var dto = _userBusinessLogic.Save(entity);
         return(LogicResult <UserDTO> .Succeed(dto));
     }
     catch (Exception exception)
     {
         return(LogicResult <UserDTO> .Failure(exception));
     }
 }
 public LogicResult Remove(Guid id)
 {
     try
     {
         _userBusinessLogic.Remove(id);
         return(LogicResult.Succeed());
     }
     catch (Exception exception)
     {
         return(LogicResult.Failure(exception));
     }
 }
 public LogicResult <IEnumerable <UserDTO> > GetAll()
 {
     try
     {
         var users = _userBusinessLogic.GetAll();
         return(LogicResult <IEnumerable <UserDTO> > .Succeed(users));
     }
     catch (Exception exception)
     {
         return(LogicResult <IEnumerable <UserDTO> > .Failure(exception));
     }
 }
 public LogicResult <UserDTO> GetById(Guid id)
 {
     try
     {
         var entity = _userBusinessLogic.GetById(id);
         return(LogicResult <UserDTO> .Succeed(entity));
     }
     catch (Exception exception)
     {
         return(LogicResult <UserDTO> .Failure(exception));
     }
 }
Exemple #14
0
 public LogicResult <ProductInvoiceModel> GetProductInvoice(Guid productId)
 {
     try
     {
         var product = Store.CartProducts.FirstOrDefault(m => m.Id == productId);
         return(LogicResult <ProductInvoiceModel> .Succeed(Mapper.Map <ProductInvoiceModel>(product)));
     }
     catch
     {
         return(LogicResult <ProductInvoiceModel> .Failure(Validation.UnSuccessfullOperation));
     }
 }
Exemple #15
0
 public LogicResult <PaymentDetail> CalculatePrice(PriceDetail priceDetail)
 {
     try
     {
         var calculation   = this.GetCalculation(priceDetail.Type);
         var paymentDetail = calculation.CalculatePrice(priceDetail);
         return(LogicResult <PaymentDetail> .Succeed(paymentDetail));
     }
     catch (Exception exception)
     {
         return(LogicResult <PaymentDetail> .Failure(exception));
     }
 }
Exemple #16
0
        public LogicResult <PaymentDetail> CalculatePrice(PriceDetail priceDetail)
        {
            var paymentDetailResult = _priceCalculationService.CalculatePrice(priceDetail);

            if (paymentDetailResult.IsSucceed)
            {
                return(LogicResult <PaymentDetail> .Succeed(paymentDetailResult.Data));
            }
            else
            {
                return(LogicResult <PaymentDetail> .Failure(Validation.UnSuccessfullOperation));
            }
        }
        public LogicResult <IEnumerable <ProductDTO> > GetByTypeId(Guid typeId)
        {
            var result = _productService.GetAll();

            if (result.IsSucceed)
            {
                var products = result.Data.Where(m => m.TypeId == typeId);
                return(LogicResult <IEnumerable <ProductDTO> > .Succeed(products));
            }
            else
            {
                return(LogicResult <IEnumerable <ProductDTO> > .Failure(result.FailureResult.ToArray()));
            }
        }
 public LogicResult <IEnumerable <ProductCartModel> > GetProductsByUser(Guid userId)
 {
     try
     {
         var userProducts = from userToProduct in _userToProductQueryService.GetAll()
                            join product in _productQueryService.GetAll() on userToProduct.ProductId equals product.Id
                            join productType in _productTypeServiceFacade.Data on product.TypeId equals productType.Id
                            where userToProduct.UserId == userId select new ProductCartModel
         {
             Day           = userToProduct.Day,
             UserId        = userToProduct.UserId,
             Point         = userToProduct.Point,
             Id            = userToProduct.ProductId,
             PaymentDetail = SerializerHelper.DeserializeObject <PaymentDetail>(userToProduct.PaymentDetail),
             Name          = product.Name,
             Type          = productType.Type
         };
         return(LogicResult <IEnumerable <ProductCartModel> > .Succeed(userProducts));
     }
     catch
     {
         return(LogicResult <IEnumerable <ProductCartModel> > .Failure(Validation.UnSuccessfullOperation));
     }
 }
Exemple #19
0
        public LogicResult <UserDTO> Login(UserLoginModel model)
        {
            var result = _userService.GetAll();

            if (result.IsSucceed)
            {
                var user = result.Data.FirstOrDefault(m => m.Email == model.Email);
                if (user != null)
                {
                    var response = Crypto.VerifyHashedPassword(user.Password, model.Password) ? LogicResult <UserDTO> .Succeed(user) : LogicResult <UserDTO> .Failure(Resources.Validation.InvalidEmailOrPassword);

                    return(response);
                }
                else
                {
                    return(LogicResult <UserDTO> .Failure(Resources.Validation.InvalidEmailOrPassword));
                }
            }
            else
            {
                return(LogicResult <UserDTO> .Failure(Resources.Validation.UnSuccessfullOperation));
            }
        }