Example #1
0
 public static void UpdateTKBD(this TKBDAmount tkbd, TKBDAmountViewModel vm)
 {
     tkbd.Account         = vm.Account;
     tkbd.Amount          = vm.Amount;
     tkbd.CreatedBy       = vm.CreatedBy;
     tkbd.CreatedDate     = vm.CreatedDate;
     tkbd.Id              = vm.Id;
     tkbd.MetaDescription = vm.MetaDescription;
     tkbd.MetaKeyWord     = vm.MetaKeyWord;
     tkbd.Month           = vm.Month;
     tkbd.Status          = vm.Status;
     tkbd.UpdatedBy       = vm.UpdatedBy;
     tkbd.UpdatedDate     = vm.UpdatedDate;
     tkbd.Year            = vm.Year;
     tkbd.TotalMoney      = vm.TotalMoney ?? 0;
 }
Example #2
0
 public void Update(TKBDAmount tkbd)
 {
     _tKBDRepository.Update(tkbd);
 }
Example #3
0
 public TKBDAmount Add(TKBDAmount tkbd)
 {
     return(_tKBDRepository.Add(tkbd));
 }
Example #4
0
        public HttpResponseMessage Update(HttpRequestMessage request)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    int days = 0;
                    // previous month
                    var _now = int.Parse(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()) - 1;
                    var tkbdHistories = new List <TKBDHistory>();
                    // list account of previous month
                    tkbdHistories = _tkbdHistoryService.GetAll().Where(x => x.Status == true && x.TimeCode == _now).ToList();
                    int c = tkbdHistories.Count();
                    foreach (var item in tkbdHistories.ToList())
                    {
                        decimal money = _tkbdHistoryService.GetByAccount(item.Account).Where(x => x.Status == true && (x.TransactionDate.Value.Month <= DateTime.Now.Month - 1 || x.TransactionDate.Value.Year < DateTime.Now.Year)).Sum(x => x.Money) ?? 0;

                        if (money <= 0)
                        {
                            var oldTransaction = _tkbdHistoryService.GetByAccount(item.Account);
                            foreach (var item1 in oldTransaction)
                            {
                                item1.Status = false;
                            }
                        }
                        else
                        {
                            TimeSpan s = new TimeSpan();
                            DateTimeOffset lastDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1);
                            DateTimeOffset firstDayOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, 1);
                            s = lastDay.Subtract(item.TransactionDate ?? DateTimeOffset.UtcNow);
                            days = (int)s.TotalDays;
                            if (days > 31)
                            {
                                days = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month - 1);
                            }

                            //if (firstDayOfMonth > item.TransactionDate)
                            //{
                            //    s = lastDay.Subtract(firstDayOfMonth);
                            //}
                            //else
                            //{
                            //    s = lastDay.Subtract(item.TransactionDate ?? DateTimeOffset.UtcNow);
                            //}

                            //days = (int)s.TotalDays;
                            TKBDAmountViewModel vm = new TKBDAmountViewModel();
                            vm.Status = true;
                            vm.Account = item.Account;
                            vm.CreatedBy = _applicationUserService.getByUserId(item.UserId).UserName;
                            vm.UserId = item.UserId;
                            vm.Month = DateTime.Now.Month - 1;
                            vm.Year = DateTime.Now.Year;
                            vm.TotalMoney = money;
                            vm.Amount = money * item.Rate * 20 * days / 120000 / 30 ?? 0;
                            TKBDAmount tkbd = new TKBDAmount();
                            tkbd.UpdateTKBD(vm);
                            if (_tkbdService.CheckExist(vm.Account, vm.Month, vm.Year))
                            {
                                continue;
                            }
                            _tkbdService.Add(tkbd);
                        }
                        _tkbdService.Save();
                    }

                    response = request.CreateResponse(HttpStatusCode.Created, tkbdHistories.Count());
                }
                return response;
            }));
        }