コード例 #1
0
ファイル: OffenseService.cs プロジェクト: mynrd/HRIS.MVC
        public void Create(OffenseModel model, out Guid offenseId)
        {
            if (this._repoOffense.Query().Filter(x => x.code == model.code).Get().Any())
            {
                throw new Exception(model.code + " is already exists");
            }
            var currentUserId = this.GetCurrentUserId();
            var ins           = this._repoOffense.Insert(new mf_Offense()
            {
                code        = model.code,
                description = model.description,
                updatedBy   = currentUserId,
            });

            this._unitOfWork.Save();
            offenseId = ins.id;
        }
コード例 #2
0
ファイル: OffenseService.cs プロジェクト: mynrd/HRIS.MVC
        public void Update(OffenseModel model)
        {
            var upt = this._repoOffense.Find(model.id);

            if (upt.code != model.code)
            {
                if (this._repoOffense.Query().Filter(x => x.code == model.code).Get().Any())
                {
                    throw new Exception(model.code + " is already exists");
                }
                upt.code = model.code;
            }
            upt.description = model.description;
            upt.updatedBy   = this.GetCurrentUserId();
            upt.updatedDate = DateTime.Now;
            this._repoOffense.Update(upt);
            this._unitOfWork.Save();
        }
コード例 #3
0
ファイル: OffenseController.cs プロジェクト: mynrd/HRIS.MVC
        public ActionResult OffenseCRUD([DataSourceRequest] DataSourceRequest request
                                        , UpdateType updateType
                                        , OffenseModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                try
                {
                    switch (updateType)
                    {
                    case UpdateType.Create:
                        Guid offenseId;
                        this._offenseService.Create(model, out offenseId);
                        model.id = offenseId;
                        break;

                    case UpdateType.Update:
                        this._offenseService.Update(model);
                        break;

                    case UpdateType.Destroy:
                        this._offenseService.Delete(model.id.Value);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    this.AddModelError(ex);
                }
            }
            if (model.id.HasValue && updateType != UpdateType.Destroy)
            {
                model = this._offenseService.GetById(model.id.Value);
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }