public AlertMessage Edit(CollectorViewModel model) { AlertMessage alert = new AlertMessage(); if (!IsAccessible(ModuleCode.Collector)) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } if (!IsEditable()) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } IRepository <TCollector> repo = _unitOfWork.GetRepository <TCollector>(); repo.Condition = PredicateBuilder.True <TCollector>().And(x => x.NIK == model.NIK); TCollector item = repo.Find().FirstOrDefault(); if (item == null) { alert.Text = StaticMessage.ERR_DATA_NOT_FOUND; return(alert); } DateTime now = DateTime.UtcNow.ToUtcID(); item.FULLNAME = model.Fullname; item.Role = model.IsRole; item.ValidFrom = DateTime.Parse(model.FormattedValidFrom); item.ValidTo = DateTime.Parse(model.FormattedValidTo); item.UpdatedBy = _userAuth.NIK.ToString(); item.UpdatedOn = now; try { _unitOfWork.BeginTransaction(); repo.Update(item); _unitOfWork.Commit(); alert.Status = 1; alert.Text = string.Format(StaticMessage.SCS_EDIT, 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); }
public ActionResult Add(CollectorViewModel model) { AlertMessage alert = new AlertMessage(); CollectorBusiness business = new CollectorBusiness(); 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)); }
// GET: Collectors/Create public IActionResult Create() { var model = new CollectorViewModel { }; return(View(model)); }
private CollectorViewModel GetCollectorViewModel(TCollector item) { CollectorViewModel model = new CollectorViewModel(); model.NIK = (int)item.NIK; model.Fullname = item.FULLNAME; model.IsRole = item.Role; model.ValidFromDate = item.ValidFrom; model.FormattedValidFrom = item.ValidFrom.ToString(AppConstant.DefaultFormatDate); model.ValidToDate = item.ValidTo; model.FormattedValidTo = item.ValidTo.ToString(AppConstant.DefaultFormatDate); return(model); }
public CollectorViewModel getCollectorsLocationName(int?locationid) { CollectorViewModel collectorViewModel = new CollectorViewModel(); collectorViewModel = uow.Repository <CollectorViewModel>().SqlQuery("select collectorname,l.CollectorId from dbo.fgetcollectorinfo() as c inner join[dbo].[LocationVsCollector] as l on c.CollectorID = l.CollectorId where locationid = " + locationid).SingleOrDefault(); //if (collectorname == null) //{ // return ""; //} //else //{ return(collectorViewModel); //} }
private CollectorViewModel GetCollectorViewModel(DataRow dr) { CollectorViewModel model = new CollectorViewModel(); 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); }
public ActionResult Edit(int?id = null) { ViewBag.IsEdit = true; if (id == null) { return(RedirectToAction("Index")); } CollectorBusiness business = new CollectorBusiness(); CollectorViewModel model = business.GetDetail(id.Value); if (model == null) { TempData["AlertMessage"] = new AlertMessage(StaticMessage.ERR_DATA_NOT_FOUND); return(RedirectToAction("Index")); } return(View(model)); }
public AlertMessage Add(CollectorViewModel model) { AlertMessage alert = new AlertMessage(); if (!IsAccessible(ModuleCode.Collector)) { 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 <TCollector> repo = _unitOfWork.GetRepository <TCollector>(); TCollector item = null; #region check NIK exist repo.Condition = PredicateBuilder.True <TCollector>().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 TCollector() { 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); }
// ---------------------------------------------------------------------- public MainPage() { InitializeComponent(); DataContext = new CollectorViewModel(); } // MainPage
// ---------------------------------------------------------------------- public MainPage() { InitializeComponent(); DataContext = new CollectorViewModel(); }