Esempio n. 1
0
        // добавление новой заявки
        public void AddElement(Request model)
        {
            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    Request element = new Request
                    {
                        Id            = model.Id,
                        Date          = model.Date,
                        Address       = model.Address,
                        ReceiptMark   = false,
                        DateReception = null,
                        Prioritet     = model.Prioritet,
                        UserId        = AuthController.authId
                    };
                    context.Requests.Add(element);
                    context.SaveChanges();
                    transaction.Commit();

                    string address = findEmail(AuthController.authId);
                    email.SendEmail(address, "Оформление заказа", "Ваш заказ на " + model.Date.ToString() + " принят в обработку");
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
        public IActionResult Remove(int id)
        {
            var deleteMe = _dbContext.Students.Single(x => x.Id == id);

            _dbContext.Students.Remove(deleteMe);
            _dbContext.SaveChanges();

            return(RedirectToAction("Index", "Message",
                                    MessageVm.Create(
                                        urlService: Url,
                                        message: "Student is removed.",
                                        returnAction: "Index",
                                        returnController: "Student"
                                        )
                                    ));
        }
Esempio n. 3
0
 //регистрация нового пользователя
 public void AddElement(User model)
 {
     using (var transaction = context.Database.BeginTransaction())
     {
         try
         {
             User element = context.Users.FirstOrDefault(rec =>
                                                         rec.Login == model.Login);
             if (element != null)
             {
                 throw new Exception("Уже есть пользователь с таким логином");
             }
             string encryptedPass = service.Encrypt("Login", model.Password);
             element = new User
             {
                 FIO         = model.FIO,
                 CompanyName = model.CompanyName,
                 Login       = model.Login,
                 Password    = encryptedPass,
                 Email       = model.Email,
                 PhoneNumber = model.PhoneNumber,
                 Role        = model.Role
             };
             context.Users.Add(element);
             context.SaveChanges();
             transaction.Commit();
         }
         catch (Exception)
         {
             transaction.Rollback();
             throw;
         }
     }
 }
Esempio n. 4
0
        public void rateProvider(int providerId, decimal rate)
        {
            Provider element = getById(providerId);

            element.Rating = (element.Rating + rate) / 2;
            context.SaveChanges();
        }
Esempio n. 5
0
        private void AddNewTraffic()
        {
            if (cbxFrom.SelectedItem == cbxTo.SelectedItem)
            {
                MessageBox.Show("Операция Отклонена! Указанные города должны быть разными.");
                return;
            }

            if (idCargoesToList.Count == 0)
            {
                MessageBox.Show("Добавьте груз");
                return;
            }
            Traffic traffic = new Traffic
            {
                IdAirplane    = (cbxAirplanes.Items[cbxAirplanes.SelectedIndex] as Airplane).Id,
                IdAirportFrom = (cbxFrom.Items[cbxFrom.SelectedIndex] as Airport).Id,
                IdAirportTo   = (cbxTo.Items[cbxTo.SelectedIndex] as Airport).Id
            };

            var cargos = db.Cargoes
                         .Where(c => idCargoesToList.Contains(c.Id))
                         .ToList();

            cargos.ForEach(c => traffic.Cargos.Add(c));



            //db.Entry(traffic).State = EntityState.Modified;
            db.Traffics.Add(traffic);
            db.SaveChanges();
            this.Close();
        }
Esempio n. 6
0
        public ActionResult AddStudent(int courseId, int studentId)
        {
            var course  = _dbContext.Courses.Single(x => x.Id == courseId);
            var student = _dbContext.Students.Single(x => x.Id == studentId);

            course.Students.Add(student);
            _dbContext.SaveChanges();

            return(RedirectToAction("Index", "Message",
                                    MessageVm.Create(
                                        urlService: Url,
                                        message: "Student was sucessfully enrolled in course.",
                                        returnAction: "Index",
                                        returnController: "Enrollment",
                                        routeValues: new { CourseId = courseId }
                                        )
                                    ));
        }
Esempio n. 7
0
        private void ChangeAirplaneData()
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxNameAir.Text) &&
                    string.IsNullOrEmpty(textBoxMaxDistance.Text) &&
                    string.IsNullOrEmpty(textBoxCarrying.Text))
                {
                    return;
                }

                var airplane = GetSelectedAirplane();

                if (airplane == null)
                {
                    return;
                }

                var newAirplane = new Airplane();

                if (!string.IsNullOrEmpty(textBoxNameAir.Text))
                {
                    newAirplane.Name = textBoxNameAir.Text;
                }
                else
                {
                    newAirplane.Name = airplane.Name;
                }

                if (!string.IsNullOrEmpty(textBoxMaxDistance.Text))
                {
                    newAirplane.MaxDistance = Int32.Parse(textBoxMaxDistance.Text);
                }
                else
                {
                    newAirplane.MaxDistance = airplane.MaxDistance;
                }

                if (!string.IsNullOrEmpty(textBoxCarrying.Text))
                {
                    newAirplane.Carrying = Int32.Parse(textBoxCarrying.Text);
                }
                else
                {
                    newAirplane.Carrying = airplane.Carrying;
                }

                if (airplane.Equals(newAirplane))
                {
                    return;
                }

                airplane.Name        = newAirplane.Name;
                airplane.MaxDistance = newAirplane.MaxDistance;
                airplane.Carrying    = newAirplane.Carrying;

                ClearFieldsInput();

                db.Entry(airplane).State = EntityState.Modified;
                db.SaveChanges();
                dataGridAirplanes.Refresh();
                ShowInfo("Объект изменен!");
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }