コード例 #1
0
        // POST: odata/Warehouse
        public IHttpActionResult Post(DebtNoteViewModel delta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // TODO: Add create logic here.
            using (var unitOfWork = _unitOfWorkManager.NewUnitOfWork())
            {
                var result = _debtNote.AddDebtNote(delta);
                unitOfWork.Commit();
                var resultObject = new DebtNoteViewModel()
                {
                    Id               = result.Id,
                    isOwed           = result.IsOwed,
                    CreatedDate      = result.CreatedDate,
                    LastModifiedDate = result.LastModifiedDate,
                    Total            = result.Total,
                    Code             = result.Code,
                    PaymentTypeId    = result.PaymentType.Id,
                    WarehouseId      = result.PayWarehouse.Id
                };
                return(Created(resultObject));
            }
        }
コード例 #2
0
        public IHttpActionResult Put(Guid key, DebtNoteViewModel delta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var unitOfWork = _unitOfWorkManager.NewUnitOfWork())
            {
                _debtNote.UpdateDebtNote(delta);
                unitOfWork.Commit();
                return(StatusCode(HttpStatusCode.OK));
            }
        }
コード例 #3
0
ファイル: DebtNoteService.cs プロジェクト: Nanapj/inventory
 public DebtNote AddDebtNote(DebtNoteViewModel model)
 {
     if (Queryable().Any(x => x.Code.ToLower().Contains(model.Code.ToLower()) && x.Delete == false))
     {
         throw new Exception("Đã tồn tại mã phiếu");
     }
     else
     {
         var result = new DebtNote();
         var User   = _userRepository.Find(HttpContext.Current.User.Identity.GetUserId()) ?? _userRepository.GetAll().FirstOrDefault();
         if (model.isOwed == false)
         {
             result.Code = "OWN" + DateTime.Now.ToString("yy") + DateTime.Now.ToString("MM") + (Queryable().Where(x => x.IsOwed == false &&
                                                                                                                  x.CreatedDate.Month == DateTime.Now.Month &&
                                                                                                                  x.CreatedDate.Year == DateTime.Now.Year).Count() + 1).ToString("D4");
             result.Index      = Queryable().Where(x => x.IsOwed == false).Count() + 1;
             result.MonthIndex = Queryable().Where(x => x.IsOwed == false &&
                                                   x.CreatedDate.Month == DateTime.Now.Month &&
                                                   x.CreatedDate.Year == DateTime.Now.Year).Count() + 1;
         }
         else
         {
             result.Code = "OWED" + DateTime.Now.ToString("yy") + DateTime.Now.ToString("MM") + (Queryable().Where(x => x.IsOwed == true &&
                                                                                                                   x.CreatedDate.Month == DateTime.Now.Month &&
                                                                                                                   x.CreatedDate.Year == DateTime.Now.Year).Count() + 1).ToString("D4");
             result.Index      = Queryable().Where(x => x.IsOwed == true).Count() + 1;
             result.MonthIndex = Queryable().Where(x => x.IsOwed == true &&
                                                   x.CreatedDate.Month == DateTime.Now.Month &&
                                                   x.CreatedDate.Year == DateTime.Now.Year).Count() + 1;
         }
         result.User             = _userRepository.Find(HttpContext.Current.User.Identity.GetUserId()) ?? _userRepository.GetAll().FirstOrDefault();
         result.CreatedDate      = DateTime.Now;
         result.LastModifiedDate = DateTime.Now;
         result.Total            = model.Total;
         result.IsOwed           = model.isOwed;
         result.PaymentType      = _paymentType.Find(model.PaymentTypeId);
         result.PayWarehouse     = _warehouse.Find(model.WarehouseId);
         result.Noted            = model.Noted;
         Insert(result);
         return(result);
     }
 }
コード例 #4
0
ファイル: DebtNoteService.cs プロジェクト: Nanapj/inventory
        public bool UpdateDebtNote(DebtNoteViewModel model)
        {
            var DebtNote = Find(model.Id.Value);

            if (DebtNote != null)
            {
                DebtNote.Total            = model.Total;
                DebtNote.PaymentType      = _paymentType.Find(model.PaymentTypeId);
                DebtNote.PayWarehouse     = _warehouse.Find(model.WarehouseId);
                DebtNote.IsOwed           = model.isOwed;
                DebtNote.LastModifiedDate = DateTime.Now;
                DebtNote.Noted            = model.Noted;
                Update(DebtNote);
                return(true);
            }
            else
            {
                throw new Exception("Phiếu không tồn tại");
            }
        }