public async Task <int> SubmitAsync(int id, int userId) { var model = await _prescriptionRespository.GetIndexAsync(id); var list = await _prescriptionGoodsRespository.GetListAsync(id); var goods = list.Select(x => new StoreChangeGoodsValueModel { HospitalGoodId = x.HospitalGoods.Id, ChangeQty = x.Qty, Recrdno = RecordNumber.Next((int)StoreChangeType.Prescription, x.Id), }); using (var trans = _defaultDbTransaction.Begin()) { _storeContext.BatchCreateOrUpdate(new BatchStoreChangeApiModel { ChangeTypeId = (int)StoreChangeType.Prescription, HospitalChangeGoods = goods.ToList(), }, model.HospitalDepartment.Id, userId); _prescriptionRespository.UpdateStatus(id, PrescriptionStatus.Submited); trans.Commit(); } return(0); }
public async Task <PrescriptionIndexApiModel> GetIndexAsync(int id) { var sql = from p in _context.Prescription join u in _context.User on p.CreateUserId equals u.Id join d in _context.HospitalDepartment on p.HospitalDepartmentId equals d.Id where p.Id == id select new PrescriptionIndexApiModel { Cardno = p.Cardno, CreateTime = p.CreateTime, CreateUserName = u.Username, Id = p.Id, Status = p.Status, HospitalDepartment = new GetHospitalDepartmentResponse { Id = p.HospitalDepartmentId }, }; var data = sql.FirstOrDefault(); if (data != null) { data.PrescriptionGoods = await _prescriptionGoodsRespository.GetListAsync(id); } return(data); }