public ActionResult Add(SalesmanViewModel model) { AlertMessage alert = new AlertMessage(); SalesmanBusiness business = new SalesmanBusiness(); if (!ModelState.IsValid) { alert.Text = string.Join(System.Environment.NewLine, ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)); } else { business.SetUserAuth(ViewBag.UserAuth); alert = business.Add(model); } TempData["AlertMessage"] = alert; if (alert.Status == 1) { return(RedirectToAction("Index")); } return(View("Edit", model)); }
//public OnStockProductViewModel(Product product): base(product) //{ // var orderedTransactions = product.Transactions.OrderBy(x => x.Date); // var transactionBought = orderedTransactions.LastOrDefault(x => x.TypeID == (int) TranType.Bought); // if (transactionBought != null) // { // DateBought = transactionBought.Date; // SalesmanBought = new SalesmanViewModel(transactionBought.Operator.Salesman); // } // var lastTransaction = orderedTransactions.LastOrDefault(); // if (lastTransaction != null) // { // LastTransactionDate = lastTransaction.Date; // } //} public OnStockProductViewModel(IGrouping <ModelSerialNumberStatusPriceBoughtGroup, Product> products) : base(products.FirstOrDefault()) { IDs = products.Select(x => x.ID).ToList(); Product firstProduct = products.FirstOrDefault(); if (firstProduct == null) { return; } var orderedTransactions = firstProduct.Transactions.OrderBy(x => x.Date); var transactionBought = orderedTransactions.LastOrDefault(x => x.TypeID == (int)TranType.Bought); if (transactionBought != null) { DateBought = transactionBought.Date; SalesmanBought = new SalesmanViewModel(transactionBought.Operator.Salesman); } var lastTransaction = orderedTransactions.LastOrDefault(); if (lastTransaction != null) { LastTransactionDate = lastTransaction.Date; } }
public MobileTransactionViewModel(MobileTransaction mobileTransaction) { ID = mobileTransaction.ID; MobileOperator = new MobileOperatorViewModel(mobileTransaction.MobileOperator); CreditSum = mobileTransaction.CreditSum; if (mobileTransaction.Transaction.Price != null) Price = mobileTransaction.Transaction.Price.Value; if (mobileTransaction.Transaction.Contragent != null) Client = new ContragentViewModel(mobileTransaction.Transaction.Contragent); Salesman = new SalesmanViewModel(mobileTransaction.Transaction.Operator.Salesman); Date = mobileTransaction.Transaction.Date; Profit = Price - CreditSum; }
public ActionResult Create() { SalesmanViewModel salesman = new SalesmanViewModel(); using (DB5Entities5 db = new DB5Entities5()) { salesman.CompanyCollection = db.Comapnies.ToList <Comapny>(); } return(View(salesman)); }
public ToPawnProductViewModel(Product product) : base(product) { var orderedTransactions = product.Transactions.OrderBy(x => x.Date); var transactionToPawn = orderedTransactions.LastOrDefault(x => x.TypeID == (int)TranType.ToPawn); if (transactionToPawn != null) { DateTake = transactionToPawn.Date; Client = new ClientViewModel(transactionToPawn.Contragent.Client); SalesmanTake = new SalesmanViewModel(transactionToPawn.Operator.Salesman); } }
public ActionResult Delete(int?id, SalesmanViewModel obj) { try { var v = db.Salesmen.Where(a => a.SalesmanID == id).First(); db.Entry(v).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
private SalesmanViewModel GetSalesmanViewModel(SLM slm) { SalesmanViewModel model = new SalesmanViewModel(); model.NIK = slm.NIK; model.Fullname = slm.FullName; model.IsRole = slm.Role; model.ValidFromDate = slm.ValidFrom; model.ValidToDate = slm.ValidTo; model.FormattedValidFrom = model.ValidFromDate.ToString(AppConstant.DefaultFormatDate); model.FormattedValidTo = model.ValidToDate.ToString(AppConstant.DefaultFormatDate); return(model); }
public EditSalesmanDialogViewModel(MainViewModel mainViewModel) { _mainViewModel = mainViewModel; _salesmanToEdit = new SalesmanViewModel(mainViewModel.Context.Salesmen.FirstOrDefault( x => x.ID == mainViewModel.SalesmenViewModel.SelectedContragent.ID)); EditSalesmanCommand = new DelegateCommand(EditSalesman, Validate); FirstName = _salesmanToEdit.FirstName; LastName = _salesmanToEdit.LastName; Login = _salesmanToEdit.Login; ProfitPercentage = _salesmanToEdit.ProfitPercentage; SalaryPerDay = _salesmanToEdit.SalaryPerDay; }
private SalesmanViewModel GetSalesmanViewModel(RHHeader item) { SalesmanViewModel model = new SalesmanViewModel() { NIK = item.SLMObj1.NIK, Fullname = item.SLMObj1.FullName, IsRole = item.SLMObj1.Role, ValidFromDate = item.ValidFrom, ValidToDate = item.ValidTo }; model.FormattedValidFrom = item.ValidFrom.ToString(AppConstant.DefaultFormatDate); model.FormattedValidTo = item.ValidTo.ToString(AppConstant.DefaultFormatDate); return(model); }
public MobileTransactionViewModel(MobileTransaction mobileTransaction) { ID = mobileTransaction.ID; MobileOperator = new MobileOperatorViewModel(mobileTransaction.MobileOperator); CreditSum = mobileTransaction.CreditSum; if (mobileTransaction.Transaction.Price != null) { Price = mobileTransaction.Transaction.Price.Value; } if (mobileTransaction.Transaction.Contragent != null) { Client = new ContragentViewModel(mobileTransaction.Transaction.Contragent); } Salesman = new SalesmanViewModel(mobileTransaction.Transaction.Operator.Salesman); Date = mobileTransaction.Transaction.Date; Profit = Price - CreditSum; }
public ActionResult Edit(int?id, SalesmanViewModel obj) { try { //db.Salesmen.Find(id).SalesmanID = obj.SalesmanID; db.Salesmen.Find(id).Name = obj.Name; db.Salesmen.Find(id).Phone = obj.Phone; db.Salesmen.Find(id).CompanyID = obj.CompanyID; db.Salesmen.Find(id).StockID = obj.StockID; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public SalesmanViewModel GetDetail(int id) { IRepository <SLM> repo = _unitOfWork.GetRepository <SLM>(); repo.Condition = PredicateBuilder.True <SLM>().And(x => x.NIK == id); SLM slm = repo.Find().FirstOrDefault(); if (slm == null) { return(null); } SalesmanViewModel model = GetSalesmanViewModel(slm); return(model); }
// GET: Salesman/Delete/5 public ActionResult Delete(int?id) { SalesmanViewModel obj = new SalesmanViewModel(); Salesman s = db.Salesmen.Find(id); if (s == null) { return(HttpNotFound()); } else { obj.SalesmanID = s.SalesmanID; obj.Name = s.Name; obj.Phone = s.Phone; obj.CompanyID = s.CompanyID; obj.StockID = s.StockID; } return(View(obj)); }
public ToRepairProductViewModel(Product product) : base(product) { var orderedTransactions = product.Transactions.OrderBy(x => x.Date); var firstToRepairTransaction = orderedTransactions.FirstOrDefault(x => x.TypeID == (int) TranType.ToRepair); if (firstToRepairTransaction != null && firstToRepairTransaction.Contragent != null && firstToRepairTransaction.Contragent.Client != null) { Client = new ClientViewModel(firstToRepairTransaction.Contragent.Client); } var lastTransaction = orderedTransactions.LastOrDefault(); if (lastTransaction != null) { LastTransactionDate = lastTransaction.Date; LastTransactionSalesman = new SalesmanViewModel(lastTransaction.Operator.Salesman); CurrentRepairer = (lastTransaction.Contragent == null || lastTransaction.Contragent.Repairer == null) ? null : new RepairerViewModel(lastTransaction.Contragent.Repairer); } }
public ActionResult Create(SalesmanViewModel obj) { try { Salesman s = new Salesman(); s.Name = obj.Name; s.CNIC = obj.CNIC; s.Phone = obj.Phone; s.CompanyID = obj.CompanyID; s.StockID = obj.StockID; db.Salesmen.Add(s); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
public ToRepairProductViewModel(Product product) : base(product) { var orderedTransactions = product.Transactions.OrderBy(x => x.Date); var firstToRepairTransaction = orderedTransactions.FirstOrDefault(x => x.TypeID == (int)TranType.ToRepair); if (firstToRepairTransaction != null && firstToRepairTransaction.Contragent != null && firstToRepairTransaction.Contragent.Client != null) { Client = new ClientViewModel(firstToRepairTransaction.Contragent.Client); } var lastTransaction = orderedTransactions.LastOrDefault(); if (lastTransaction != null) { LastTransactionDate = lastTransaction.Date; LastTransactionSalesman = new SalesmanViewModel(lastTransaction.Operator.Salesman); CurrentRepairer = (lastTransaction.Contragent == null || lastTransaction.Contragent.Repairer == null) ? null : new RepairerViewModel(lastTransaction.Contragent.Repairer); } }
public ActionResult Edit(int?id = null) { ViewBag.IsEdit = true; if (id == null) { return(RedirectToAction("Index")); } SalesmanBusiness business = new SalesmanBusiness(); SalesmanViewModel model = business.GetDetail(id.Value); if (model == null) { TempData["AlertMessage"] = new AlertMessage(StaticMessage.ERR_DATA_NOT_FOUND); return(RedirectToAction("Index")); } return(View(model)); }
private SalesmanViewModel GetSalesmanViewModel(DataRow dr) { SalesmanViewModel model = new SalesmanViewModel(); model.NIK = dr.IsNull("NIK") ? 0 : Convert.ToInt32(dr["NIK"]); model.Fullname = dr.IsNull("FullName") ? null : dr["FullName"].ToString(); model.IsRole = dr.IsNull("Role") ? false : Convert.ToBoolean(dr["Role"]); if (!dr.IsNull("ValidFrom")) { model.ValidFromDate = Convert.ToDateTime(dr["ValidFrom"]); model.FormattedValidFrom = model.ValidFromDate.ToString(AppConstant.DefaultFormatDate); } if (!dr.IsNull("ValidTo")) { model.ValidToDate = Convert.ToDateTime(dr["ValidTo"]); model.FormattedValidTo = model.ValidToDate.ToString(AppConstant.DefaultFormatDate); } return(model); }
// GET: Salesman public ActionResult Index() { try { List <Salesman> list = db.Salesmen.ToList(); List <SalesmanViewModel> viewList = new List <SalesmanViewModel>(); foreach (Salesman s in list) { SalesmanViewModel obj = new SalesmanViewModel(); obj.SalesmanID = s.SalesmanID; obj.Name = s.Name; obj.CNIC = s.CNIC; obj.Phone = s.Phone; obj.CompanyID = s.CompanyID; obj.StockID = s.StockID; viewList.Add(obj); } return(View(viewList)); } catch (Exception ex) { throw ex; } }
//public OnStockProductViewModel(Product product): base(product) //{ // var orderedTransactions = product.Transactions.OrderBy(x => x.Date); // var transactionBought = orderedTransactions.LastOrDefault(x => x.TypeID == (int) TranType.Bought); // if (transactionBought != null) // { // DateBought = transactionBought.Date; // SalesmanBought = new SalesmanViewModel(transactionBought.Operator.Salesman); // } // var lastTransaction = orderedTransactions.LastOrDefault(); // if (lastTransaction != null) // { // LastTransactionDate = lastTransaction.Date; // } //} public OnStockProductViewModel(IGrouping<ModelSerialNumberStatusPriceBoughtGroup, Product> products) : base(products.FirstOrDefault()) { IDs = products.Select(x => x.ID).ToList(); Product firstProduct = products.FirstOrDefault(); if (firstProduct == null) return; var orderedTransactions = firstProduct.Transactions.OrderBy(x => x.Date); var transactionBought = orderedTransactions.LastOrDefault(x => x.TypeID == (int) TranType.Bought); if (transactionBought != null) { DateBought = transactionBought.Date; SalesmanBought = new SalesmanViewModel(transactionBought.Operator.Salesman); } var lastTransaction = orderedTransactions.LastOrDefault(); if (lastTransaction != null) { LastTransactionDate = lastTransaction.Date; } }
public AlertMessage Edit(SalesmanViewModel model) { AlertMessage alert = new AlertMessage(); if (!IsAccessible(ModuleCode.Salesman)) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } if (!IsEditable()) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } IRepository <SLM> repo = _unitOfWork.GetRepository <SLM>(); repo.Condition = PredicateBuilder.True <SLM>().And(x => x.NIK == model.NIK); SLM slm = repo.Find().FirstOrDefault(); if (slm == null) { alert.Text = StaticMessage.ERR_DATA_NOT_FOUND; return(alert); } DateTime now = DateTime.UtcNow.ToUtcID(); //IRepository<RHHeader> repoHeader = _unitOfWork.GetRepository<RHHeader>(); //repoHeader.Condition = PredicateBuilder.True<RHHeader>().And(x => x.SLM == model.NIK); //RHHeader rhHeader = repoHeader.Find().FirstOrDefault(); //if (rhHeader != null) //{ // rhHeader.ValidFrom = DateTime.Parse(model.FormattedValidFrom); // rhHeader.ValidTo = DateTime.Parse(model.FormattedValidTo); // rhHeader.UpdatedBy = _userAuth.NIK.ToString(); // rhHeader.UpdatedOn = now; //} slm.FullName = model.Fullname; //slm.Role = model.IsRole; slm.ValidFrom = DateTime.Parse(model.FormattedValidFrom); slm.ValidTo = DateTime.Parse(model.FormattedValidTo); slm.UpdatedBy = _userAuth.NIK.ToString(); slm.UpdatedOn = now; try { _unitOfWork.BeginTransaction(); repo.Update(slm); //repoHeader.Update(rhHeader); _unitOfWork.Commit(); alert.Status = 1; alert.Text = string.Format(StaticMessage.SCS_EDIT, slm.NIK, slm.FullName); } catch (Exception ex) { _logger.Write("error", DateTime.Now, ex.Message, _userAuth.Fullname, ex); alert.Text = StaticMessage.ERR_SAVE_FAILED; } finally { _unitOfWork.Dispose(); } return(alert); }
public AlertMessage Add(SalesmanViewModel model) { AlertMessage alert = new AlertMessage(); if (!IsAccessible(ModuleCode.Salesman)) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } if (!IsEditable()) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } DateTime now = DateTime.UtcNow.ToUtcID(); DateTime validFrom = now.AddMonths(-1).AddDays(1).Date; DateTime validTo = new DateTime(9999, 12, 31); //model.ValidFromDate = DateTime.ParseExact(model.FormattedValidFrom, AppConstant.DefaultFormatDate, _cultureInfo); //model.ValidToDate = DateTime.ParseExact(model.FormattedValidTo, AppConstant.DefaultFormatDate, _cultureInfo); IRepository <SLM> repo = _unitOfWork.GetRepository <SLM>(); SLM item = null; #region check NIK exist repo.Condition = PredicateBuilder.True <SLM>().And(x => x.NIK == model.NIK); item = repo.Find().FirstOrDefault(); if (item != null) { alert.Text = string.Format(StaticMessage.ERR_NIK_EXIST, item.NIK); return(alert); } #endregion item = new SLM() { NIK = model.NIK, FullName = model.Fullname, Role = model.IsRole, ValidFrom = validFrom, ValidTo = validTo, CreatedBy = _userAuth.NIK.ToString(), CreatedOn = now, UpdatedBy = _userAuth.NIK.ToString(), UpdatedOn = now, }; try { _unitOfWork.BeginTransaction(); repo.Insert(item); _unitOfWork.Commit(); alert.Status = 1; alert.Text = string.Format(StaticMessage.SCS_ADD_MASTER, item.NIK, item.FullName); } catch (Exception ex) { _logger.Write("error", DateTime.Now, ex.Message, _userAuth.Fullname, ex); alert.Text = StaticMessage.ERR_SAVE_FAILED; } finally { _unitOfWork.Dispose(); } return(alert); }