public ActionResult Insert(MAgent viewModel, FormCollection formCollection) { MAgent mItemCatToInsert = new MAgent(); TransferFormValuesTo(mItemCatToInsert, viewModel); mItemCatToInsert.SetAssignedIdTo(viewModel.Id); mItemCatToInsert.CreatedDate = DateTime.Now; mItemCatToInsert.CreatedBy = User.Identity.Name; mItemCatToInsert.DataStatus = EnumDataStatus.New.ToString(); _mAgentRepository.Save(mItemCatToInsert); try { _mAgentRepository.DbContext.CommitChanges(); } catch (Exception e) { _mAgentRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
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 Commission(AgentCommViewModel viewModel, FormCollection formCollection, string agentId) { _mAgentCommRepository.DbContext.BeginTransaction(); //delete agent commission first _mAgentCommRepository.DeleteByAgent(agentId); IList <MGame> listGame = _mGameRepository.GetAll(); MGame game = null; MAgentComm comm = null; MAgent agent = _mAgentRepository.Get(agentId); string gameComm; for (int i = 0; i < listGame.Count; i++) { game = listGame[i]; comm = new MAgentComm(agent); comm.SetAssignedIdTo(Guid.NewGuid().ToString()); gameComm = formCollection[string.Format("txtComm_{0}", game.Id)]; //set comm value if comm value is not empty if (!string.IsNullOrEmpty(gameComm)) { comm.CommValue = decimal.Parse(gameComm); } comm.GameId = game; comm.DataStatus = EnumDataStatus.New.ToString(); comm.CreatedBy = User.Identity.Name; comm.CreatedDate = DateTime.Now; _mAgentCommRepository.Save(comm); } bool Success = true; string Message = string.Empty; try { _mAgentCommRepository.DbContext.CommitTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; Success = true; Message = "Komisi Agen berhasil disimpan."; } catch (Exception ex) { _mAgentCommRepository.DbContext.RollbackTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; Success = false; Message = ex.GetBaseException().Message; } var e = new { Success, Message }; return(Json(e, JsonRequestBehavior.AllowGet)); }
public static SalesViewModel Create(IMAgentRepository mAgentRepository) { SalesViewModel viewModel = new SalesViewModel(); viewModel.SalesDate = DateTime.Today; IList <MAgent> list = mAgentRepository.GetAll(); MAgent agent = new MAgent(); agent.AgentName = "-Pilih Agen-"; list.Insert(0, agent); viewModel.AgentList = new SelectList(list, "Id", "AgentName"); viewModel.SalesId = Guid.NewGuid().ToString(); return(viewModel); }
public static ReportParamViewModel Create(IMAgentRepository mAgentRepository, IMGameRepository mGameRepository) { ReportParamViewModel viewModel = new ReportParamViewModel(); IList <MAgent> list = mAgentRepository.GetAll(); MAgent costCenter = new MAgent(); costCenter.AgentName = "-Semua Agen-"; list.Insert(0, costCenter); viewModel.AgentList = new SelectList(list, "Id", "AgentName"); IList <MGame> listGame = mGameRepository.GetAll(); MGame game = new MGame(); game.GameName = "-Semua Game-"; listGame.Insert(0, game); viewModel.GameList = new SelectList(listGame, "Id", "GameName"); viewModel.DateFrom = DateTime.Today; viewModel.DateTo = DateTime.Today; return(viewModel); }
public ActionResult Delete(MAgent viewModel, FormCollection formCollection) { MAgent mItemCatToDelete = _mAgentRepository.Get(viewModel.Id); if (mItemCatToDelete != null) { _mAgentRepository.Delete(mItemCatToDelete); } try { _mAgentRepository.DbContext.CommitChanges(); } catch (Exception e) { _mAgentRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public ActionResult Update(MAgent viewModel, FormCollection formCollection) { MAgent mItemCatToUpdate = _mAgentRepository.Get(viewModel.Id); TransferFormValuesTo(mItemCatToUpdate, viewModel); mItemCatToUpdate.ModifiedDate = DateTime.Now; mItemCatToUpdate.ModifiedBy = User.Identity.Name; mItemCatToUpdate.DataStatus = EnumDataStatus.Updated.ToString(); _mAgentRepository.Update(mItemCatToUpdate); try { _mAgentRepository.DbContext.CommitChanges(); } catch (Exception e) { _mAgentRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
private void TransferFormValuesTo(MAgent mItemCatToUpdate, MAgent mItemCatFromForm) { mItemCatToUpdate.AgentName = mItemCatFromForm.AgentName; mItemCatToUpdate.AgentDesc = mItemCatFromForm.AgentDesc; }