Ejemplo n.º 1
0
        public IActionResult Create(AchIngredient newItem)
        {
            var newId = _context.AchIngredient.OrderByDescending(i => i.IdIngredient).FirstOrDefault().IdIngredient + 1;

            newItem.IdIngredient = newId;

            _context.AchIngredient.Add(newItem);
            _context.SaveChanges();
            return(StatusCode(201, newItem));
        }
        public IActionResult Create(AchOrderPizza newItem)
        {
            var newId = _context.AchOrderPizza.OrderByDescending(i => i.IdOrderPizza).FirstOrDefault().IdOrderPizza + 1;

            newItem.IdOrderPizza = newId;

            _context.AchOrderPizza.Add(newItem);
            _context.SaveChanges();
            return(StatusCode(201, newItem));
        }
        public IActionResult Create(AchCustomerAlergen newItem)
        {
            var newId = _context.AchCustomerAlergen.OrderByDescending(i => i.CustomerAlergenId).FirstOrDefault().CustomerAlergenId + 1;

            newItem.CustomerAlergenId = newId;


            _context.AchCustomerAlergen.Add(newItem);
            _context.SaveChanges();
            return(StatusCode(201, newItem));
        }
        public IActionResult Create(AchCustomer newCustomer)
        {
            var newId = _context.AchCustomer.OrderByDescending(i => i.IdCustomer).FirstOrDefault().IdCustomer + 1;

            newCustomer.IdCustomer = newId;


            _context.AchCustomer.Add(newCustomer);
            _context.SaveChanges();
            return(StatusCode(201, newCustomer));
        }
Ejemplo n.º 5
0
        public IActionResult Create(AchAdditive newItem)
        {
            var newId = _context.AchAdditive.OrderByDescending(i => i.IdAdditive).FirstOrDefault().IdAdditive + 1;

            newItem.IdAdditive = newId;


            _context.AchAdditive.Add(newItem);
            _context.SaveChanges();
            return(StatusCode(201, newItem));
        }
        public IActionResult Create(AchPizzaComposition newItem)
        {
            var newId = _context.AchPizzaComposition.OrderByDescending(i => i.PizzaCompositionId).FirstOrDefault().PizzaCompositionId + 1;

            newItem.PizzaCompositionId = newId;


            _context.AchPizzaComposition.Add(newItem);
            _context.SaveChanges();
            return(StatusCode(201, newItem));
        }
Ejemplo n.º 7
0
        public IActionResult Deletepizza(Pizza pizza)
        {
            if (_context.Pizza.Count(e => e.Id == pizza.Id) == 0)
            {
                return(NotFound());
            }

            _context.Pizza.Remove(pizza);
            _context.SaveChanges();

            return(Ok(pizza));
        }
        public IActionResult Update(int item_id, AchOrderAdditive updated_item)
        {
            var item = _context.AchOrderAdditive.Count(e => e.IdOrderAddiive == item_id);


            if (item == 0)
            {
                return(NotFound());
            }

            updated_item.IdOrderAddiive = item_id;
            _context.AchOrderAdditive.Attach(updated_item);
            _context.Entry(updated_item).State = EntityState.Modified;
            _context.SaveChanges();
            return(Ok(updated_item));
        }
Ejemplo n.º 9
0
        [Route("api/students/modifyStudent")] //zmień na student
        public IActionResult ModifyStudent(ModifyStudentRequest request)
        {
            var db = new _2019SBDContext();


            var s = new Student
            {
                IndexNumber = request.IndexNumber,
                FirstName   = request.FirstName,
                LastName    = request.LastName,
                BirthDate   = request.BirthDate
            };

            db.Attach(s);

            if (request.FirstName != null)
            {
                db.Entry(s).Property("FirstName").IsModified = true;
            }

            if (request.LastName != null)
            {
                db.Entry(s).Property("LastName").IsModified = true;
            }

            if (request.BirthDate != null)
            {
                db.Entry(s).Property("BirthDate").IsModified = true;
            }

            db.SaveChanges();
            var db2 = new _2019SBDContext();


            var res = db2.Student
                      .Where(d => d.IndexNumber == request.IndexNumber)
                      .FirstOrDefault();



            var response = new ModifyStudentResponse();

            response.IndexNumber = res.IndexNumber;
            response.FirstName   = res.FirstName;
            response.LastName    = res.LastName;
            response.BirthDate   = res.BirthDate;



            return(Ok(response));
        }
Ejemplo n.º 10
0
        [Route("api/students/deleteStudent")] //zmień na student
        public IActionResult DeleteStudent(ModifyStudentRequest request)
        {
            var db      = new _2019SBDContext();
            var student = new Student
            {
                IndexNumber = request.IndexNumber
            };

            db.Attach(student);
            db.Remove(student);


            db.SaveChanges();
            return(Ok(request.IndexNumber + " zostal usunięty"));
        }
Ejemplo n.º 11
0
 public IActionResult CreateOrder(Zamowienie order)
 {
     _context.Zamowienie.Add(order);
     _context.SaveChanges();
     return(StatusCode(201, order)); //201
 }
Ejemplo n.º 12
0
 public IActionResult CreateClient(Klient client)
 {
     _context.Klient.Add(client);
     _context.SaveChanges();
     return(StatusCode(201, client));
 }
Ejemplo n.º 13
0
        public IActionResult EnrollStudent(EnrollStudentRequest request)
        {
            var db = new _2019SBDContext();

            var res = db.Studies
                      .Where((d) => d.Name == request.Studies).FirstOrDefault();

            if (res == null)
            {
                return(BadRequest());
            }



            var db2  = new _2019SBDContext();
            var res2 = db2.Enrollment
                       .Where(d => d.Semester == 1 && d.IdStudy == res.IdStudy)
                       .OrderByDescending(d => d.StartDate) //rosnąco czy malejąco?
                       .FirstOrDefault();

            EnrollStudentResponse esr = new EnrollStudentResponse();

            if (res2 == null)
            {
                //wyszukaj największ idEnrollment

                var res3 = db.Enrollment
                           .OrderByDescending(d => d.IdEnrollment) //rosnąco czy malejąco?
                           .FirstOrDefault();

                int maxIdEnrollment = res3.IdEnrollment;
                //ZMIEŃ UWAGA NA DATE teraz


                esr.StartDate = DateTime.Today;
                //stworz nowy
                var e = new Enrollment()
                {
                    IdEnrollment = maxIdEnrollment + 1,
                    StartDate    = esr.StartDate,
                    Semester     = 1,
                    IdStudy      = res.IdStudy
                };

                db.Enrollment.Add(e);
                esr.IdEnrollment = maxIdEnrollment + 1;

                //    db.SaveChanges();//póżniej zlikwidować !!!!!1111
            }
            else
            {
                esr.IdEnrollment = res2.IdEnrollment;
            }



            //  var db4 = new _2019SBDContext();
            var res4 = db2.Student
                       .Where(d => d.IndexNumber == request.IndexNumber).FirstOrDefault();

            if (res4 != null)
            {
                return(BadRequest());
            }



            //DODAJ STUDENTA      //sprawdzić jak się savuje bez tamtego
            var s = new Student()
            {
                IndexNumber  = request.IndexNumber,
                FirstName    = request.FirstName,
                LastName     = request.LastName,
                BirthDate    = request.BirthDate,
                IdEnrollment = esr.IdEnrollment
            };

            db.Student.Add(s);

            db.SaveChanges();//póżniej zlikwidować !!!!!1111

            esr.IndexNumber = s.IndexNumber;
            esr.Studies     = request.Studies;
            esr.Semester    = 1;
            var res5 = db2.Enrollment
                       .Where(d => d.IdEnrollment == esr.IdEnrollment).FirstOrDefault();

            esr.StartDate = res5.StartDate;



            return(Ok(esr));
        }
Ejemplo n.º 14
0
        [Route("api/enrollments/promotions")] //zmień na student
        public IActionResult PromoteStudents(PromoteStudentsRequest request)
        {
            var db = new _2019SBDContext();
            //  var res = db.Student.ToList();


            var res = db.Studies
                      .Where((d) => d.Name == request.Studies).FirstOrDefault();

            if (res == null)
            {
                return(BadRequest());
            }

            var res2 = db.Enrollment
                       .Where((d) => d.IdStudy == res.IdStudy && d.Semester == request.Semester).FirstOrDefault();

            if (res == null)
            {
                return(BadRequest());
            }

            var res3 = db.Enrollment
                       .Where((d) => d.IdStudy == res.IdStudy && d.Semester == request.Semester + 1).FirstOrDefault();

            PromoteStudentsResponse response = new PromoteStudentsResponse();

            if (res3 == null)
            {
                //dodaj enrollment



                var res4 = db.Enrollment
                           .OrderByDescending(d => d.IdEnrollment) //rosnąco czy malejąco?
                           .FirstOrDefault();

                int maxIdEnrollment = res4.IdEnrollment;


                response.StartDate = DateTime.Today;

                var e = new Enrollment()
                {
                    IdEnrollment = maxIdEnrollment + 1,
                    StartDate    = response.StartDate,
                    Semester     = request.Semester + 1,
                    IdStudy      = res.IdStudy
                };

                db.Enrollment.Add(e);
                response.IdEnrollment = maxIdEnrollment + 1;
            }
            else
            {
                response.IdEnrollment = res3.IdEnrollment;
            }

            //    db.SaveChanges();



            //teraz trzeba wszystkich studentów zrolować
            var res5 = db.Student
                       .Where((d) => d.IdEnrollment == res2.IdEnrollment).ToList();


            foreach (Student s in res5)
            {
                s.IdEnrollment = response.IdEnrollment;
            }



            db.SaveChanges();



            return(Ok(response));
        }