Beispiel #1
0
 public async Task <bool> EditReceive(List <Receive_Detail> data, string user)
 {
     // Lay update_by tu List<Receive_Detail> dua ve Receive_Detail
     data = data.Select(x =>
     {
         x.Update_By = user;
         return(x);
     }).ToList();
     foreach (var item in data)
     {
         var receiveDetail = new Receive_Detail();
         receiveDetail.ID          = item.ID;
         receiveDetail.CatID       = item.CatID;
         receiveDetail.CatName     = item.CatName;
         receiveDetail.ReceiveID   = item.ReceiveID;
         receiveDetail.ProductID   = item.ProductID;
         receiveDetail.ProductName = item.ProductName;
         receiveDetail.Qty         = item.Qty;
         receiveDetail.Update_By   = item.Update_By;
         receiveDetail.Update_Time = DateTime.Now;
         _repoReceiveDetail.Update(receiveDetail);
     }
     try
     {
         return(await _repoReceiveDetail.SaveAll());
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
        public async Task <bool> ReceiveRegister(List <ReceiveDetailModel> data, string userId)
        {
            // Thêm vào bảng Receive
            var receiveID    = CodeUtility.RandomString();
            var receiveModel = new Receive_Dto();

            receiveModel.ID            = receiveID;
            receiveModel.UserID        = userId;
            receiveModel.Register_Date = DateTime.Now;
            receiveModel.Updated_Time  = DateTime.Now;
            receiveModel.Status        = "0";
            var user = await _serverUser.GetUserById(userId);

            receiveModel.DepID = user.DepID;
            var receive = _mapper.Map <Receive>(receiveModel);

            _repoReceive.Add(receive);

            // Thêm vào bảng Receive Detail
            foreach (var item in data)
            {
                var receiveDetail = new Receive_Detail();
                receiveDetail.CatID       = item.CatID;
                receiveDetail.CatName     = item.CatName;
                receiveDetail.ReceiveID   = receive.ID;
                receiveDetail.ProductID   = item.ProductID;
                receiveDetail.ProductName = item.ProductName;
                receiveDetail.Qty         = item.Qty;
                receiveDetail.Update_Time = DateTime.Now;
                _repoReceiveDetail.Add(receiveDetail);
            }

            try
            {
                return(await _repoReceiveDetail.SaveAll());
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }