public ActionResult Add(ASMViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            ASMBusiness business = new ASMBusiness();

            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"));
            }

            ViewBag.ListRayonType = business.GetListRayonType();

            return(View("Edit", model));
        }
Exemple #2
0
        private ASMViewModel GetASMViewModel(ASM item)
        {
            ASMViewModel model = new ASMViewModel();

            model.NIK                    = item.NIK;
            model.Fullname               = item.FullName;
            model.DefaultRayonType       = item.DefaultRayonType;
            model.IsRole                 = item.Role;
            model.AllowWriteBy           = item.AllowedByNIK;
            model.IsAbleToUpload         = item.AllowedByNIK == null ? false : true;
            model.UploadValidTo          = item.UploadValidTo;
            model.FormattedUploadValidTo = item.UploadValidTo == null ? null : item.UploadValidTo.Value.ToString(AppConstant.DefaultFormatDate);
            model.ValidFromDate          = item.ValidFrom;
            model.ValidToDate            = item.ValidTo;
            model.FormattedValidFrom     = model.ValidFromDate.ToString(AppConstant.DefaultFormatDate);
            model.FormattedValidTo       = model.ValidToDate.ToString(AppConstant.DefaultFormatDate);

            return(model);
        }
Exemple #3
0
        private ASMViewModel GetASMViewModel(DataRow dr)
        {
            ASMViewModel model = new ASMViewModel();

            model.NIK                    = dr.IsNull("NIK") ? 0 : Convert.ToInt32(dr["NIK"]);
            model.Fullname               = dr.IsNull("FullName") ? null : dr["FullName"].ToString();
            model.DefaultRayonType       = dr.IsNull("DefaultRayonType") ? null : dr["DefaultRayonType"].ToString();
            model.IsRole                 = dr.IsNull("Role") ? false : Convert.ToBoolean(dr["Role"]);
            model.AllowWriteBy           = dr.IsNull("AllowedByNIK") ? (int?)null : Convert.ToInt32(dr["AllowedByNIK"]);
            model.IsAbleToUpload         = model.AllowWriteBy == null ? false : true;
            model.UploadValidTo          = dr.IsNull("UploadValidTo") ? (DateTime?)null : Convert.ToDateTime(dr["UploadValidTo"]);
            model.FormattedUploadValidTo = model.UploadValidTo == null ? "" : model.UploadValidTo.Value.ToString(AppConstant.DefaultFormatDate);
            model.ValidFromDate          = Convert.ToDateTime(dr["ValidFrom"]);
            model.ValidToDate            = Convert.ToDateTime(dr["ValidTo"]);

            model.FormattedValidFrom = model.ValidFromDate.ToString(AppConstant.DefaultFormatDate);
            model.FormattedValidTo   = model.ValidToDate.ToString(AppConstant.DefaultFormatDate);

            return(model);
        }
        public ActionResult Edit(int?id = null)
        {
            ViewBag.IsEdit = true;

            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            ASMBusiness business = new ASMBusiness();

            ASMViewModel model = business.GetDetail(id.Value);

            if (model == null)
            {
                TempData["AlertMessage"] = new AlertMessage(StaticMessage.ERR_DATA_NOT_FOUND);

                return(RedirectToAction("Index"));
            }

            ViewBag.ListRayonType = business.GetListRayonType();

            return(View(model));
        }
Exemple #5
0
        public AlertMessage Edit(ASMViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!IsAccessible(ModuleCode.ASM))
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            if (!IsEditable())
            {
                alert.Text = StaticMessage.ERR_ACCESS_DENIED;
                return(alert);
            }

            IRepository <ASM> repo = _unitOfWork.GetRepository <ASM>();

            repo.Condition = PredicateBuilder.True <ASM>().And(x => x.NIK == model.NIK);

            ASM 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.DefaultRayonType = model.DefaultRayonType;
            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);
        }
Exemple #6
0
        public AlertMessage Add(ASMViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            if (!IsAccessible(ModuleCode.ASM))
            {
                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 <ASM> repo = _unitOfWork.GetRepository <ASM>();
            ASM item = null;

            #region check NIK exist
            repo.Condition = PredicateBuilder.True <ASM>().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 ASM()
            {
                NIK              = model.NIK,
                FullName         = model.Fullname,
                Role             = model.IsRole,
                DefaultRayonType = model.DefaultRayonType,
                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);
        }