Beispiel #1
0
        public async Task <bool> Create(CustomerPointHistory CustomerPointHistory)
        {
            await ValidatePoint(CustomerPointHistory);
            await ValidateNote(CustomerPointHistory);

            return(CustomerPointHistory.IsValidated);
        }
Beispiel #2
0
 public async Task <bool> Delete(CustomerPointHistory CustomerPointHistory)
 {
     if (await ValidateId(CustomerPointHistory))
     {
     }
     return(CustomerPointHistory.IsValidated);
 }
Beispiel #3
0
        public async Task <bool> Delete(CustomerPointHistory CustomerPointHistory)
        {
            await DataContext.CustomerPointHistory.Where(x => x.Id == CustomerPointHistory.Id).UpdateFromQueryAsync(x => new CustomerPointHistoryDAO {
                DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow
            });

            return(true);
        }
Beispiel #4
0
 private async Task <bool> ValidatePoint(CustomerPointHistory CustomerPointHistory)
 {
     if (CustomerPointHistory.ChangePoint <= 0)
     {
         CustomerPointHistory.AddError(nameof(CustomerPointHistoryValidator), nameof(CustomerPointHistory.ChangePoint), ErrorCode.ChangePointEmpty);
     }
     return(CustomerPointHistory.IsValidated);
 }
Beispiel #5
0
 private async Task <bool> ValidateNote(CustomerPointHistory CustomerPointHistory)
 {
     if (string.IsNullOrWhiteSpace(CustomerPointHistory.Description))
     {
         CustomerPointHistory.AddError(nameof(CustomerPointHistoryValidator), nameof(CustomerPointHistory.Description), ErrorCode.DescriptionEmpty);
     }
     return(CustomerPointHistory.IsValidated);
 }
Beispiel #6
0
        public async Task <CustomerPointHistory> Get(long Id)
        {
            CustomerPointHistory CustomerPointHistory = await DataContext.CustomerPointHistory.AsNoTracking()
                                                        .Where(x => x.Id == Id)
                                                        .Where(x => x.DeletedAt == null)
                                                        .Select(x => new CustomerPointHistory()
            {
                CreatedAt    = x.CreatedAt,
                UpdatedAt    = x.UpdatedAt,
                Id           = x.Id,
                CustomerId   = x.CustomerId,
                TotalPoint   = x.TotalPoint,
                CurrentPoint = x.CurrentPoint,
                ChangePoint  = x.ChangePoint,
                IsIncrease   = x.IsIncrease,
                Description  = x.Description,
                ReduceTotal  = x.ReduceTotal,
                Customer     = x.Customer == null ? null : new Customer
                {
                    Id                 = x.Customer.Id,
                    Code               = x.Customer.Code,
                    Name               = x.Customer.Name,
                    Phone              = x.Customer.Phone,
                    Address            = x.Customer.Address,
                    NationId           = x.Customer.NationId,
                    ProvinceId         = x.Customer.ProvinceId,
                    DistrictId         = x.Customer.DistrictId,
                    WardId             = x.Customer.WardId,
                    CustomerTypeId     = x.Customer.CustomerTypeId,
                    Birthday           = x.Customer.Birthday,
                    Email              = x.Customer.Email,
                    ProfessionId       = x.Customer.ProfessionId,
                    CustomerResourceId = x.Customer.CustomerResourceId,
                    SexId              = x.Customer.SexId,
                    StatusId           = x.Customer.StatusId,
                    CompanyId          = x.Customer.CompanyId,
                    ParentCompanyId    = x.Customer.ParentCompanyId,
                    TaxCode            = x.Customer.TaxCode,
                    Fax                = x.Customer.Fax,
                    Website            = x.Customer.Website,
                    NumberOfEmployee   = x.Customer.NumberOfEmployee,
                    BusinessTypeId     = x.Customer.BusinessTypeId,
                    Investment         = x.Customer.Investment,
                    RevenueAnnual      = x.Customer.RevenueAnnual,
                    IsSupplier         = x.Customer.IsSupplier,
                    Descreption        = x.Customer.Descreption,
                    Used               = x.Customer.Used,
                    RowId              = x.Customer.RowId,
                },
            }).FirstOrDefaultAsync();

            if (CustomerPointHistory == null)
            {
                return(null);
            }

            return(CustomerPointHistory);
        }
Beispiel #7
0
        public async Task <CustomerPointHistory> Get(long Id)
        {
            CustomerPointHistory CustomerPointHistory = await UOW.CustomerPointHistoryRepository.Get(Id);

            if (CustomerPointHistory == null)
            {
                return(null);
            }
            return(CustomerPointHistory);
        }
Beispiel #8
0
        public async Task <CustomerPointHistory> Create(CustomerPointHistory CustomerPointHistory)
        {
            if (!await CustomerPointHistoryValidator.Create(CustomerPointHistory))
            {
                return(CustomerPointHistory);
            }

            try
            {
                var oldDatas = await UOW.CustomerPointHistoryRepository.List(new CustomerPointHistoryFilter
                {
                    Skip       = 0,
                    Take       = int.MaxValue,
                    Selects    = CustomerPointHistorySelect.ALL,
                    CustomerId = new IdFilter {
                        Equal = CustomerPointHistory.CustomerId
                    },
                });

                CustomerPointHistory.TotalPoint = oldDatas.Where(x => x.IsIncrease == true).Select(x => x.ChangePoint).DefaultIfEmpty(0).Sum();

                CustomerPointHistory.CurrentPoint = oldDatas.Where(x => x.IsIncrease == true).Select(x => x.ChangePoint).DefaultIfEmpty(0).Sum() -
                                                    oldDatas.Where(x => x.IsIncrease == false).Select(x => x.ChangePoint).DefaultIfEmpty(0).Sum();
                if (CustomerPointHistory.IsIncrease)
                {
                    CustomerPointHistory.TotalPoint   += CustomerPointHistory.ChangePoint;
                    CustomerPointHistory.CurrentPoint += CustomerPointHistory.ChangePoint;
                }
                else
                {
                    CustomerPointHistory.CurrentPoint -= CustomerPointHistory.ChangePoint;
                    if (CustomerPointHistory.ReduceTotal)
                    {
                        CustomerPointHistory.TotalPoint -= CustomerPointHistory.ChangePoint;
                    }
                }
                await UOW.CustomerPointHistoryRepository.Create(CustomerPointHistory);

                CustomerPointHistory = await UOW.CustomerPointHistoryRepository.Get(CustomerPointHistory.Id);

                await Logging.CreateAuditLog(CustomerPointHistory, new { }, nameof(CustomerPointHistoryService));

                return(CustomerPointHistory);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPointHistoryService));
            }
            return(null);
        }
 public Customer_CustomerPointHistoryDTO(CustomerPointHistory CustomerPointHistory)
 {
     this.Id           = CustomerPointHistory.Id;
     this.CustomerId   = CustomerPointHistory.CustomerId;
     this.TotalPoint   = CustomerPointHistory.TotalPoint;
     this.CurrentPoint = CustomerPointHistory.CurrentPoint;
     this.ChangePoint  = CustomerPointHistory.ChangePoint;
     this.IsIncrease   = CustomerPointHistory.IsIncrease;
     this.Description  = CustomerPointHistory.Description;
     this.ReduceTotal  = CustomerPointHistory.ReduceTotal;
     this.Customer     = CustomerPointHistory.Customer == null ? null : new Customer_CustomerDTO(CustomerPointHistory.Customer);
     this.CreatedAt    = CustomerPointHistory.CreatedAt;
     this.UpdatedAt    = CustomerPointHistory.UpdatedAt;
     this.Errors       = CustomerPointHistory.Errors;
 }
        public async Task <ActionResult <Customer_CustomerPointHistoryDTO> > GetCustomerPointHistory([FromBody] Customer_CustomerPointHistoryDTO Customer_CustomerPointHistoryDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CustomerPointHistory CustomerPointHistory = await CustomerPointHistoryService.Get(Customer_CustomerPointHistoryDTO.Id);

            return(new Customer_CustomerPointHistoryDTO(CustomerPointHistory));
        }
Beispiel #11
0
        public async Task <bool> ValidateId(CustomerPointHistory CustomerPointHistory)
        {
            CustomerPointHistoryFilter CustomerPointHistoryFilter = new CustomerPointHistoryFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerPointHistory.Id
                },
                Selects = CustomerPointHistorySelect.Id
            };

            int count = await UOW.CustomerPointHistoryRepository.Count(CustomerPointHistoryFilter);

            if (count == 0)
            {
                CustomerPointHistory.AddError(nameof(CustomerPointHistoryValidator), nameof(CustomerPointHistory.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Beispiel #12
0
        public async Task <CustomerPointHistory> Delete(CustomerPointHistory CustomerPointHistory)
        {
            if (!await CustomerPointHistoryValidator.Delete(CustomerPointHistory))
            {
                return(CustomerPointHistory);
            }

            try
            {
                await UOW.CustomerPointHistoryRepository.Delete(CustomerPointHistory);

                await Logging.CreateAuditLog(new { }, CustomerPointHistory, nameof(CustomerPointHistoryService));

                return(CustomerPointHistory);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPointHistoryService));
            }
            return(null);
        }
Beispiel #13
0
        public async Task <bool> Create(CustomerPointHistory CustomerPointHistory)
        {
            CustomerPointHistoryDAO CustomerPointHistoryDAO = new CustomerPointHistoryDAO();

            CustomerPointHistoryDAO.Id           = CustomerPointHistory.Id;
            CustomerPointHistoryDAO.CustomerId   = CustomerPointHistory.CustomerId;
            CustomerPointHistoryDAO.TotalPoint   = CustomerPointHistory.TotalPoint;
            CustomerPointHistoryDAO.CurrentPoint = CustomerPointHistory.CurrentPoint;
            CustomerPointHistoryDAO.ChangePoint  = CustomerPointHistory.ChangePoint;
            CustomerPointHistoryDAO.IsIncrease   = CustomerPointHistory.IsIncrease;
            CustomerPointHistoryDAO.Description  = CustomerPointHistory.Description;
            CustomerPointHistoryDAO.ReduceTotal  = CustomerPointHistory.ReduceTotal;
            CustomerPointHistoryDAO.CreatedAt    = StaticParams.DateTimeNow;
            CustomerPointHistoryDAO.UpdatedAt    = StaticParams.DateTimeNow;
            DataContext.CustomerPointHistory.Add(CustomerPointHistoryDAO);
            await DataContext.SaveChangesAsync();

            CustomerPointHistory.Id = CustomerPointHistoryDAO.Id;
            await SaveReference(CustomerPointHistory);

            return(true);
        }
Beispiel #14
0
        public async Task <bool> Update(CustomerPointHistory CustomerPointHistory)
        {
            CustomerPointHistoryDAO CustomerPointHistoryDAO = DataContext.CustomerPointHistory.Where(x => x.Id == CustomerPointHistory.Id).FirstOrDefault();

            if (CustomerPointHistoryDAO == null)
            {
                return(false);
            }
            CustomerPointHistoryDAO.Id           = CustomerPointHistory.Id;
            CustomerPointHistoryDAO.CustomerId   = CustomerPointHistory.CustomerId;
            CustomerPointHistoryDAO.TotalPoint   = CustomerPointHistory.TotalPoint;
            CustomerPointHistoryDAO.CurrentPoint = CustomerPointHistory.CurrentPoint;
            CustomerPointHistoryDAO.ChangePoint  = CustomerPointHistory.ChangePoint;
            CustomerPointHistoryDAO.IsIncrease   = CustomerPointHistory.IsIncrease;
            CustomerPointHistoryDAO.Description  = CustomerPointHistory.Description;
            CustomerPointHistoryDAO.ReduceTotal  = CustomerPointHistory.ReduceTotal;
            CustomerPointHistoryDAO.UpdatedAt    = StaticParams.DateTimeNow;
            await DataContext.SaveChangesAsync();

            await SaveReference(CustomerPointHistory);

            return(true);
        }
Beispiel #15
0
        public async Task <CustomerPointHistory> Update(CustomerPointHistory CustomerPointHistory)
        {
            if (!await CustomerPointHistoryValidator.Update(CustomerPointHistory))
            {
                return(CustomerPointHistory);
            }
            try
            {
                var oldData = await UOW.CustomerPointHistoryRepository.Get(CustomerPointHistory.Id);

                await UOW.CustomerPointHistoryRepository.Update(CustomerPointHistory);

                CustomerPointHistory = await UOW.CustomerPointHistoryRepository.Get(CustomerPointHistory.Id);

                await Logging.CreateAuditLog(CustomerPointHistory, oldData, nameof(CustomerPointHistoryService));

                return(CustomerPointHistory);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerPointHistoryService));
            }
            return(null);
        }
Beispiel #16
0
 private async Task SaveReference(CustomerPointHistory CustomerPointHistory)
 {
 }