示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("personid,lastname,firstname,address,city")] persons persons)
        {
            if (id != persons.personid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(persons);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!personsExists(persons.personid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(persons));
        }
 // Remove this line, we pass it into the function below
 /* persons p = new persons(); */
 public void add_data(persons p)
 {
     try{
         // same code as before
     }catch (Exception e) {
         // same code
     }
     finally{
         // same
     }
 }
示例#3
0
        public IActionResult Get(long id)
        {
            persons persons = _dataRepository.Get(id);

            if (persons == null)
            {
                return(NotFound("The Employee record couldn't be found."));
            }

            return(Ok(persons));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("personid,lastname,firstname,address,city")] persons persons)
        {
            if (ModelState.IsValid)
            {
                persons.personid = persons.personid != 0? _context.persons.Max(p => p.personid) + 1:0;
                _context.Add(persons);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(persons));
        }
示例#5
0
        public IActionResult Delete(long id)
        {
            persons persons = _dataRepository.Get(id);

            if (persons == null)
            {
                return(NotFound("The Employee record couldn't be found."));
            }

            _dataRepository.Delete(persons);
            return(NoContent());
        }
示例#6
0
        public IActionResult Post([FromBody] persons persons)
        {
            if (persons == null)
            {
                return(BadRequest("Employee is null."));
            }

            _dataRepository.Add(persons);
            return(CreatedAtRoute(
                       "Get",
                       new { Id = persons.EmployeeId },
                       persons));
        }
示例#7
0
        public IActionResult Put(long id, [FromBody] persons persons)
        {
            if (persons == null)
            {
                return(BadRequest("Employee is null."));
            }

            persons person = _dataRepository.Get(id);

            if (person == null)
            {
                return(NotFound("The Employee record couldn't be found."));
            }

            _dataRepository.Update(person, persons);
            return(NoContent());
        }
示例#8
0
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // ToolStripItem clickedItem = sender as ToolStripItem;
            using (DataBase db = new DataBase())
            {
                var        Result = MessageBox.Show("Вы уверены что хотите удалить данную запись?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                persToWork persW  = db.persToWork.FirstOrDefault(obj => obj.id == id);
                try
                {
                    if (Result == DialogResult.Yes)
                    {
                        logs lg = new logs();
                        lg.idUser    = this.idUser;
                        lg.typeSql   = "Delete";
                        lg.nameTable = "perstToWork, persons";
                        lg.fielTable = "all";
                        lg.oldValue  = persW.id + " " + persW.persons.surname + " " + persW.persons.name + " " + persW.persons.patronymic + " " + persW.persons.birthday + " " + persW.persons.gender + " " +
                                       //persW.persons.addressCountry + " " + persW.persons.addressRegion + " " + persW.persons.addressArea + " " + persW.persons.addressCity + " " + persW.persons.addressStreet + " " + persW.persons.addressHome + " " + persW.persons.addressFlat + " " +
                                       persW.persons.addressCity + " " + persW.persons.addressStreet + " " + persW.persons.addressHome +
                                       persW.persons.typeQualification.nameQualification + " " + persW.persons.trainingDirection + " " + persW.persons.profile + " " + persW.persons.yeatIssue + " " +
                                       persW.nameStateOrg + " " + persW.nameOrg + " " + persW.post + " " + persW.freeWork.nameFreeWork + " " + persW.numCertificate + " " + persW.numReference + " " + persW.verificationArrival + " " + persW.commentary;
                        lg.dateCrt = DateTime.Now;
                        db.logs.Add(lg);

                        int     id = persW.idPers.Value;
                        persons pe = db.persons.FirstOrDefault(obj => obj.id == id);
                        db.persons.Remove(pe);

                        //db.persToWork.Remove(persW);
                        db.SaveChanges();
                        MessageBox.Show("Запись удалена");
                    }
                }
                catch { MessageBox.Show("Данной перосны уже нет обновит таблицу нажав на кнопку поиск"); }
            }
        }
示例#9
0
        private void MBut_savePersCard_Click_1(object sender, EventArgs e)
        {
            using (DataBase db = new DataBase())
            {
                try
                {
                    if (idPers == 0 && idUser != 0)
                    {
                        #region INSERT новая персона

                        int qid = mComboB_qualificationLevel.Text == "бакалавр" ? 1 : 2;
                        typeQualification TQ = new typeQualification();
                        TQ.nameQualification = qid.ToString();

                        persons ps = new persons();
                        ps.idTypeQualification = qid;
                        ps.surname             = mTextB_surname.Text.Trim();
                        ps.name           = mTextB_name.Text.Trim();
                        ps.patronymic     = mTextB_patronymic.Text.Trim();
                        ps.birthday       = dateTime_birthday.Value;
                        ps.gender         = mComboB_gender.Text.Trim();
                        ps.addressCountry = mTextB_addressCountry.Text.Trim();
                        // ps.addressRegion = mTextB_addressRegion.Text.Trim();
                        // ps.addressArea = mTextB_addressArea.Text.Trim();
                        ps.addressCity   = mTextB_addressCity.Text.Trim();
                        ps.addressStreet = mTextB_addressStreet.Text.Trim();
                        ps.addressHome   = mTextB_addressHome.Text.Trim();
                        // ps.addressFlat = mTextB_addressFlat.Text.Trim();
                        ps.trainingDirection = mTextB_trainingDirection.Text.Trim();
                        ps.profile           = mTextB_profile.Text.Trim();
                        ps.yeatIssue         = mTextB_yearIssue.Text == "" ? ps.yeatIssue = 1970 : Convert.ToInt16(mTextB_yearIssue.Text.Trim());
                        db.persons.Add(ps);
                        idPers = ps.id;

                        int      IDFW = db.freeWork.FirstOrDefault(p => p.nameFreeWork == mComboB_freeWork.Text.Trim()).id;
                        freeWork fW   = new freeWork();
                        fW.nameFreeWork = IDFW.ToString();

                        persToWork pTW = new persToWork();
                        pTW.idPers         = idPers;
                        pTW.idFreeWork     = IDFW;
                        pTW.nameStateOrg   = mTextB_nameStateOrg.Text.Trim();
                        pTW.educational    = mTextB_educational.Text.Trim();
                        pTW.nameOrg        = mTextB_nameOrg.Text.Trim();
                        pTW.cityOrg        = mTextB_cityOrg.Text.Trim();
                        pTW.post           = mTextB_post.Text.Trim();
                        pTW.numCertificate = mTextB_numCertificate.Text.Trim();
                        pTW.numReference   = mTextB_numReference.Text.Trim();

                        pTW.verificationArrival = mComboB_verificationArrival.Text == "в наличии" ? "T" : "F";
                        pTW.commentary          = mTextB_commentary.Text.Trim();
                        pTW.dateCrt             = DateTime.Now;
                        db.persToWork.Add(pTW);

                        logs lg = new logs();
                        lg.idUser    = this.idUser;
                        lg.typeSql   = "Insert";
                        lg.nameTable = "typeQualification, persons, freeWork, persToWork";
                        lg.newValue  = idPers + " " + mTextB_surname.Text.Trim() + " " + mTextB_name.Text.Trim() + " " + mTextB_patronymic.Text.Trim() + " " + dateTime_birthday.Value + " " + mComboB_gender.Text.Trim() +
                                       " " + mTextB_addressCountry.Text + " " + mTextB_addressCity.Text.Trim() + " " + mTextB_addressStreet.Text.Trim() + " " + mTextB_addressHome.Text.Trim() +
                                       //+" "+mTextB_addressRegion.Text+" "+mTextB_addressArea.Text+" "+mTextB_addressArea.Text+" "+mTextB_addressCity.Text+" " +mTextB_addressStreet.Text+ " "+mTextB_addressHome.Text+" "+mTextB_addressFlat.Text +
                                       " " + mComboB_qualificationLevel.Text.Trim() + " " + mTextB_trainingDirection.Text.Trim() + " " + mTextB_profile.Text.Trim() + " " + mTextB_yearIssue.Text.Trim() + " " + mComboB_freeWork.Text.Trim() +
                                       " " + mTextB_nameStateOrg.Text.Trim() + " " + mTextB_educational.Text.Trim() + "" + mTextB_nameOrg.Text.Trim() + " " + mTextB_cityOrg.Text.Trim() + " " + mTextB_post.Text.Trim() + " " + mTextB_numCertificate.Text.Trim() + " " + mTextB_numReference.Text.Trim() + " " + mComboB_verificationArrival.Text.Trim() + " " + mTextB_commentary.Text.Trim();
                        lg.dateCrt = DateTime.Now;
                        db.logs.Add(lg);
                        MessageBox.Show("Запись добавлена");
                        #endregion
                    }

                    else
                    {
                        #region UPDATE Изменение информации о персоне
                        persToWork pTW = db.persToWork.FirstOrDefault(p => p.id == idPers);
                        logs       lg  = new logs();
                        lg.idUser  = this.idUser;
                        lg.typeSql = "Update";
                        //lg.fielTable = pTW;
                        // lg.nametable = "typeQualification, persons, freeWork, persToWork";
                        lg.oldValue = pTW.id + " " + pTW.persons.surname + " " + pTW.persons.name + " " + pTW.persons.patronymic + " " + pTW.persons.birthday + " " + pTW.persons.gender +
                                      //" " + pTW.persons.addressRegion + " " + pTW.persons.addressArea + " " + pTW.persons.addressCity + " " + pTW.persons.addressStreet + " " + pTW.persons.addressHome + " " + pTW.persons.addressFlat +
                                      " " + pTW.persons.addressCountry + " " + pTW.persons.addressCity + " " + pTW.persons.addressStreet + " " + pTW.persons.addressHome + " " +
                                      " " + pTW.persons.typeQualification.nameQualification + " " + pTW.persons.trainingDirection + " " + pTW.persons.profile + " " + pTW.persons.yeatIssue +
                                      " " + pTW.nameStateOrg + " " + pTW.educational + " " + pTW.nameOrg + " " + pTW.cityOrg + " " + pTW.post + " " + pTW.freeWork.nameFreeWork + " " + pTW.numCertificate + " " + pTW.numReference + " " + pTW.verificationArrival + " " + pTW.commentary;
                        lg.dateCrt = DateTime.Now;

                        pTW.persons.surname    = mTextB_surname.Text.Trim();
                        pTW.persons.name       = mTextB_name.Text.Trim();
                        pTW.persons.patronymic = mTextB_patronymic.Text.Trim();
                        pTW.persons.birthday   = dateTime_birthday.Value;
                        pTW.persons.gender     = mComboB_gender.Text.Trim();

                        pTW.persons.addressCountry = mTextB_addressCountry.Text;
                        // pTW.persons.addressRegion = mTextB_addressRegion.Text;
                        // pTW.persons.addressArea = mTextB_addressArea.Text;
                        pTW.persons.addressCity   = mTextB_addressCity.Text.Trim();
                        pTW.persons.addressStreet = mTextB_addressStreet.Text.Trim();
                        pTW.persons.addressHome   = mTextB_addressHome.Text.Trim();
                        //  pTW.persons.addressFlat = mTextB_addressFlat.Text;

                        pTW.persons.typeQualification.nameQualification = mComboB_qualificationLevel.Text.Trim();
                        pTW.persons.trainingDirection = mTextB_trainingDirection.Text.Trim();
                        pTW.persons.profile           = mTextB_profile.Text.Trim();
                        //pTW.persons.yeatIssue = Convert.ToInt16(mTextB_yearIssue.Text.Trim());
                        pTW.persons.yeatIssue = mTextB_yearIssue.Text == "" ? pTW.persons.yeatIssue = 1970 : Convert.ToInt16(mTextB_yearIssue.Text.Trim());

                        pTW.nameStateOrg = mTextB_nameStateOrg.Text.Trim();
                        pTW.educational  = mTextB_educational.Text.Trim();
                        pTW.nameOrg      = mTextB_nameOrg.Text.Trim();
                        pTW.cityOrg      = mTextB_cityOrg.Text.Trim();
                        pTW.post         = mTextB_post.Text.Trim();

                        //pTW.freeWork.nameFreeWork = mComboB_freeWork.Text.Trim();
                        string fw2 = mComboB_freeWork.SelectedItem.ToString().Trim();
                        pTW.idFreeWork          = db.freeWork.FirstOrDefault(pp => pp.nameFreeWork == fw2).id;
                        pTW.numCertificate      = mTextB_numCertificate.Text.Trim();
                        pTW.numReference        = mTextB_numReference.Text.Trim();
                        pTW.verificationArrival = mComboB_verificationArrival.Text == "в наличии" ? "T" : "F";
                        pTW.commentary          = mTextB_commentary.Text.Trim();
                        pTW.dateCrt             = DateTime.Now;

                        lg.newValue = idPers + " " + mTextB_surname.Text.Trim() + " " + mTextB_name.Text.Trim() + " " + mTextB_patronymic.Text.Trim() + " " + dateTime_birthday.Value + " " + mComboB_gender.Text.Trim() +
                                      // " " + mTextB_addressRegion.Text + " " + mTextB_addressArea.Text + " " + mTextB_addressArea.Text + " " + mTextB_addressCity.Text + " " + mTextB_addressStreet.Text + " " + mTextB_addressHome.Text + " " + mTextB_addressFlat.Text +
                                      " " + mTextB_addressCountry.Text + " " + mTextB_addressCity.Text.Trim() + " " + mTextB_addressStreet.Text.Trim() + " " + mTextB_addressHome.Text.Trim() + " " +
                                      " " + mComboB_qualificationLevel.Text.Trim() + " " + mTextB_trainingDirection.Text.Trim() + " " + mTextB_profile.Text.Trim() + " " + mTextB_yearIssue.Text.Trim() + " " + mComboB_freeWork.Text.Trim() +
                                      " " + mTextB_nameStateOrg.Text.Trim() + " " + mTextB_educational.Text.Trim() + " " + mTextB_nameOrg.Text.Trim() + " " + mTextB_cityOrg.Text.Trim() + " " + mTextB_post.Text.Trim() + " " + mTextB_numCertificate.Text.Trim() + " " + mTextB_numReference.Text.Trim() + " " + mComboB_verificationArrival.Text.Trim() + " " + mTextB_commentary.Text.Trim();
                        db.logs.Add(lg);
                        MessageBox.Show("Данные изменены");
                        #endregion
                    }
                    db.SaveChanges();
                    Close();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
        }