private TSales SaveTrans(TMsg m, string agentId, string salesNo, DateTime salesDate) { TSales sales = new TSales(); sales.SetAssignedIdTo(Guid.NewGuid().ToString()); sales.SalesDate = salesDate; sales.SalesNo = salesNo; if (!string.IsNullOrEmpty(agentId)) { MAgent agent = _mAgentRepository.Get(agentId); if (agent == null) { throw new Exception("Kode Agen salah atau tidak terdaftar"); } sales.AgentId = agent; } else { throw new Exception("Kode Agen kosong."); } sales.MsgId = m; sales.CreatedDate = DateTime.Now; sales.CreatedBy = Environment.UserName; sales.DataStatus = EnumDataStatus.New.ToString(); sales.SalesDets.Clear(); _tSalesRepository.Save(sales); return(sales); }
public ActionResult Sales(SalesViewModel viewModel, FormCollection formCollection) { _tSalesRepository.DbContext.BeginTransaction(); TSales sales = _tSalesRepository.Get(viewModel.SalesId); if (sales != null) { _tSalesRepository.Delete(sales); } sales = new TSales(); sales.SetAssignedIdTo(Guid.NewGuid().ToString()); sales.SalesDate = viewModel.SalesDate; sales.SalesNo = viewModel.SalesNo; if (!string.IsNullOrEmpty(viewModel.AgentId)) { sales.AgentId = _mAgentRepository.Get(viewModel.AgentId); } sales.CreatedDate = DateTime.Now; sales.CreatedBy = User.Identity.Name; sales.DataStatus = EnumDataStatus.New.ToString(); sales.SalesDets.Clear(); _tSalesRepository.Save(sales); SaveSalesDets(sales, formCollection); bool Success = true; string Message = string.Empty; try { _tSalesRepository.DbContext.CommitTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; Success = true; Message = "Penjualan berhasil disimpan."; } catch (Exception ex) { _tSalesRepository.DbContext.RollbackTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; Success = false; Message = ex.GetBaseException().Message; } var e = new { Success, Message }; return(Json(e, JsonRequestBehavior.AllowGet)); }
private TSales SaveTrans(string agentId, string salesNo) { TSales sales = new TSales(); sales.SetAssignedIdTo(Guid.NewGuid().ToString()); sales.SalesDate = DateTime.Today; sales.SalesNo = salesNo; if (!string.IsNullOrEmpty(agentId)) { sales.AgentId = _mAgentRepository.Get(agentId); } sales.CreatedDate = DateTime.Now; sales.CreatedBy = Environment.UserName; sales.DataStatus = EnumDataStatus.New.ToString(); sales.SalesDets.Clear(); _tSalesRepository.Save(sales); return(sales); }