Exemplo n.º 1
0
        public IActionResult AddEdit(AddEditPosition model)
        {
            ServiceResult result;

            if (!string.IsNullOrEmpty(model.Id))
            {
                var comModel = _positionService.Get(c => c.Name == model.Name);
                if (comModel != null && comModel.Id != model.Id.ToObjectId())
                {
                    return(Json(ServiceResult.IsFailed("岗位名已存在")));
                }

                var entity = model.MapTo <Position>();
                entity.UpdateDateTime  = DateTime.Now;
                entity.AdministratorId = CurrentUserData.UserId.ToObjectId();
                result = _positionService.Update(entity.Id.ToString(), entity);
            }
            else
            {
                var isExist = _positionService.Exists(c => c.Name == model.Name);
                if (isExist)
                {
                    return(Json(ServiceResult.IsFailed("岗位名已存在")));
                }

                var entity = model.MapTo <Position>();
                entity.UpdateDateTime  = DateTime.Now;
                entity.AdministratorId = CurrentUserData.UserId.ToObjectId();
                result = _positionService.Add(entity);
            }

            return(Json(result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsNameEmpty())
            {
                return;
            }

            var Position = new Position();

            if (PositionService.IsNameExisted(txtName.Text.Trim()))
            {
                MessageBox.Show("This " + txtName.Text.Trim() + " already exists.");
            }
            else
            {
                Position.Name = txtName.Text;
                PositionService.Add(Position);
            }

            ReloadForm();
        }