public async Task <bool> ReceiveRegister(Receive_Dto model) { model.ID = this.RandomString(); model.Register_Date = DateTime.Now; model.Updated_Time = DateTime.Now; model.Status = "0"; var receive = _mapper.Map <Receive>(model); _repoReceive.Add(receive); return(await _repoReceive.SaveAll()); }
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; } }