public IActionResult AddPersonal([Bind("Name, Surname, PhoneNumber, DepartmantId, ManagerId")] PersonalAddView personal)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Personal newPersonal = new Personal
                    {
                        DepartmantId = Convert.ToInt32(personal.DepartmantId),
                        ManagerId    = Convert.ToInt32(personal.ManagerId),
                        Name         = personal.Name,
                        Surname      = personal.Surname,
                        PhoneNumber  = personal.PhoneNumber
                    };
                    _personalService.Add(newPersonal);
                    return(RedirectToAction("Index", "Home"));
                }
                catch
                {
                    ViewBag.error = "Personal could not added";
                    return(RedirectToAction("AddPersonal"));
                }
            }

            ViewBag.error = "Please fill the blank fields correctly.";
            return(RedirectToAction("AddPersonal"));
        }
コード例 #2
0
        public async Task <bool> AddPersonal(Personal item)
        {
            var   resultitem = _personalService.Add(item);
            await resultitem;

            return(resultitem.IsCompleted);
        }
コード例 #3
0
        public async Task <IActionResult> Create(PersonalViewModel model, IFormFile personalImage)
        {
            await Bind();

            if (!ModelState.IsValid)
            {
                _model.Personal = model.Personal;


                return(View(_model));
            }

            var fileName = FileUpload(personalImage);

            if (personalImage != null && !string.IsNullOrEmpty(fileName))
            {
                model.Personal.PersonalImage = fileName;
            }
            if (model.Personal.PersonalId != 0)
            {
                if (GetLoginUser() != null)
                {
                    model.Personal.LastModified = GetLoginUser().UserName;
                }

                model.Personal.LastModifiedDate = DateTime.Now;
                model.Personal.IsNewItem        = false;
                var   updatePersonal = _personal.Update(model.Personal);
                await updatePersonal;
                if (updatePersonal.IsCompleted)
                {
                    alertUi.AlertUiType = updatePersonal.IsCompleted ? AlertUiType.success : AlertUiType.error;
                    CleaCache();
                }
            }
            else
            {
                model.Personal.CreationDate = DateTime.Now;
                model.Personal.IsNewItem    = true;

                if (GetLoginUser() != null)
                {
                    model.Personal.CreatedBy = GetLoginUser().UserName;
                }
                var   addPersonal = _personal.Add(model.Personal);
                await addPersonal;
                if (addPersonal.IsCompleted)
                {
                    alertUi.AlertUiType = addPersonal.IsCompleted ? AlertUiType.success : AlertUiType.error;
                    CleaCache();
                }
            }

            AlertUiMessage();



            return(RedirectToAction("Index", model));
        }
コード例 #4
0
        public async Task <IActionResult> Create(PersonalViewModel model, IFormFile personalImage)
        {
            try
            {
                await Bind();

                if (!ModelState.IsValid)
                {
                    _model.Personal = model.Personal;


                    return(View(_model));
                }

                var fileName = FileUpload(personalImage);
                if (personalImage != null && !string.IsNullOrEmpty(fileName))
                {
                    model.Personal.PersonalImage = fileName;
                }
                if (model.Personal.PersonalId != 0)
                {
                    model.Personal.CreationDate     = DateTime.Now;
                    model.Personal.LastModifiedDate = DateTime.Now;
                    model.Personal.Cinsiyet         = _model.CinsiyetList.Select(x => new Cinsiyet()
                    {
                        CinsiyeId    = Convert.ToInt32(x.Value),
                        CinsiyetName = x.Text
                    })
                                                      .FirstOrDefault(x => x.CinsiyeId == model.Personal.Cinsiyet.CinsiyeId);

                    var   updatePersonal = _personal.Update(model.Personal);
                    await updatePersonal;
                    if (updatePersonal.IsCompleted)
                    {
                        alertUi.AlertUiType = updatePersonal.IsCompleted ? AlertUiType.success : AlertUiType.error;
                    }
                }
                else
                {
                    model.Personal.CreationDate = DateTime.Now;

                    var   addPersonal = _personal.Add(model.Personal);
                    await addPersonal;
                    if (addPersonal.IsCompleted)
                    {
                        alertUi.AlertUiType = addPersonal.IsCompleted ? AlertUiType.success : AlertUiType.error;
                    }
                }

                AlertUiMessage();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(RedirectToAction("Index", model));
        }
コード例 #5
0
        public IActionResult Add(Personal personal)
        {
            var result = _personalService.Add(personal);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
コード例 #6
0
        /// <summary>
        /// Add new famer
        /// </summary>
        /// <param name="entity">Famer infomation</param>
        /// <returns></returns>
        public override ChangeDataResult Add(Famer entity)
        {
            ChangeDataResult result;

            if (entity.Personal == null)
            {
                result = ChangeDataResult.Fails(new ChangeDataError
                {
                    Code        = MessageCode.DATA_VALIDATE_ERROR,
                    Description = "Phải điền đầy đủ thông tin về nông dân"
                });
                return(result);
            }
            result = Validate(entity);
            //validate entity faild
            if (!result.Succeeded)
            {
                return(result);
            }
            _unitOfWork.BeginTransaction();
            try
            {
                //add personal
                result = _personalService.Add(entity.Personal);
                //add personal fail
                if (!result.Succeeded)
                {
                    return(result);
                }
                //add personal success
                //then add employee
                entity.Id = Guid.NewGuid();
                _famerRepository.Add(entity);
                _unitOfWork.Commit();
                _unitOfWork.SaveChanges();
                return(result);
            }
            catch (Exception ex)
            {
                _unitOfWork.RollBack();
                return(ChangeDataResult.Fails(new ChangeDataError
                {
                    Code = MessageCode.SQL_ACTION_ERROR,
                    Description = ex.Message
                }));
            }
        }
コード例 #7
0
        public override ChangeDataResult Add(Employee entity)
        {
            ChangeDataResult result;

            _unitOfWork.BeginTransaction();
            try
            {
                if (entity == null)
                {
                    throw new ArgumentNullException();
                }
                Personal personal = entity.Personal;
                result = _personalService.Add(personal);
                if (!result.Succeeded)
                {
                    return(result);
                }
                result = Validate(entity);
                if (!result.Succeeded)
                {
                    return(result);
                }
                entity.Id = Guid.NewGuid();
                _employeeRepository.Add(entity);
                _unitOfWork.Commit();
                _unitOfWork.SaveChanges();
                return(result);
            }
            catch (Exception ex)
            {
                _unitOfWork.RollBack();
                return(ChangeDataResult.Fails(new ChangeDataError
                {
                    Code = MessageCode.SQL_ACTION_ERROR,
                    Description = ex.Message
                }));
            }
        }
コード例 #8
0
        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            PersonalEkleFormModel model = new PersonalEkleFormModel();



            try
            {
                model.Kisi.KisiId  = Convert.ToInt64(txtTcNo.Text);
                model.Kisi.Isim    = txtIsim.Text;
                model.Kisi.SoyIsim = txtSoyIsim.Text;
                _kisiService.Add(model.Kisi);
                MessageBox.Show(txtIsim.Text + " " + txtSoyIsim.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            try
            {
                model.Personal.PersonalId = _personalId;
                model.Personal.KisiId     = Convert.ToInt64(txtTcNo.Text);
                model.Personal.Adi        = txtIsim.Text;
                model.Personal.Soyadi     = txtSoyIsim.Text;
                model.Personal.BolumId    = Convert.ToInt32(txtBolumId);
                model.Personal.Mail       = myEmailTextEdit1.Text;
                model.Personal.Sifre      = Convert.ToInt32(txtSifre.Text);
                _personalService.Add(model.Personal);
                MessageBox.Show("Personal Olarak Eklendi");
                this.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: AhmetKayar/WebInfo
        public async Task <bool> AddPersonal(Personal item)
        {
            await _personalService.Add(item);

            return(true);
        }