public IActionResult Create(StudentViewModel student)
        {
            _context.Students.Add(student);
            _context.SaveChanges();

            return(CreatedAtRoute("GetTodo", new { id = student.Id }, student));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "IfnsCode,IfnsName,Order")] Ifns ifns)
        {
            if (ModelState.IsValid)
            {
                db.TIfns.Add(ifns);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ifns));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "IfnsCode,CameraImgLink,CameraImgFile,CameraDisable,CameraDisableDescription,CameraAuthUser,CameraAuthPassword")] General general)
        {
            if (ModelState.IsValid)
            {
                db.TGeneral.Add(general);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(this.Index(general.IfnsCode));
            }

            ViewBag.IfnsCode = new SelectList(db.TIfns, "IfnsCode", "IfnsName", general.IfnsCode);
            return(View(general));
        }
        public ApiStudentController(ContextDatabase context)
        {
            _context = context;

            if (_context != null && !_context.Students.Any())
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                _context.Students.Add(new StudentViewModel()
                {
                    Name = "Student 1", Address = "Address 1", Email = "Email 1"
                });
                _context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public bool Create(Venta venta, DetalleVenta detalleVenta)
        {
            try
            {
                if (venta.ventaId == 0)
                {
                    _contextDatabase.Venta.Add(venta);
                }
                else
                {
                    _contextDatabase.Entry(venta).State = EntityState.Modified;
                }

                foreach (var item in venta.DetalleVenta)
                {
                    if (item.DetalleVentaId == 0)
                    {
                        _contextDatabase.DetalleVenta.Add(item);
                    }
                    else
                    {
                        _contextDatabase.Entry(item).State = EntityState.Modified;
                    }
                }

                foreach (var item in venta.DetalleVenta.SelectMany(sub => sub.SubDetalleVenta))
                {
                    if (item.DetalleVentaId == 0)
                    {
                        _contextDatabase.SubDetalleVenta.Add(item);
                    }
                    else
                    {
                        _contextDatabase.Entry(item).State = EntityState.Modified;
                    }
                }
                _contextDatabase.SaveChanges();
                return(true);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        public ActionResult Edit([Bind(Include = "Id,CameraDisable,CameraDisableDescription")] General general)
        {
            //if (ModelState.IsValid)
            if (general != null)
            {
                General modelGeneral = db.TGeneral.Find(general.Id);
                modelGeneral.CameraDisable            = general.CameraDisable;
                modelGeneral.CameraDisableDescription = general.CameraDisableDescription;

                db.TGeneral.Attach(modelGeneral);
                db.Entry(modelGeneral).Property(x => x.CameraDisable).IsModified            = true;
                db.Entry(modelGeneral).Property(x => x.CameraDisableDescription).IsModified = true;
                db.SaveChanges();
                return(this.Index(modelGeneral.IfnsCode));
            }
            ViewBag.IfnsCode = new SelectList(db.TIfns, "IfnsCode", "IfnsName", general.IfnsCode);
            if (general != null)
            {
                ViewBag.g = general;
            }
            return(View(general));
        }
Ejemplo n.º 7
0
        public ActionResult Setting(ICollection <Configuration> listConfiguration)
        {
            if (listConfiguration == null || listConfiguration.Count == 0)
            {
                throw new HttpException(400, "Некорректный запрос");
            }

            string errors = "";

            foreach (Configuration configuration in listConfiguration)
            {
                if (db.Entry(configuration).GetValidationResult().IsValid)
                {
                    db.Entry(configuration).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    foreach (var s in db.Entry(configuration).GetValidationResult().ValidationErrors)
                    {
                        errors += s.ErrorMessage + " Id: " + configuration.Id + " <br />";
                    }
                }
            }

            if (errors == "")
            {
                ViewBag.SaveState = "OK";
                ViewBag.StateText = "Данные успешно сохранены!";
            }
            else
            {
                ViewBag.SaveState = "Erorr";
                ViewBag.StateText = errors;
            }

            return(this.Setting());
        }
Ejemplo n.º 8
0
        public ActionResult AddCustomer(FormCollection form)
        {
            var      carID     = int.Parse(form["CarID"]);
            var      result1   = _db.Reservations.Where(x => x != null);
            var      datestart = DateTime.Parse(form["Start"]);
            var      dateend   = DateTime.Parse(form["End"]);
            int      counta    = 0;
            TimeSpan datecmp   = new TimeSpan();
            TimeSpan datecmp2  = new TimeSpan();

            foreach (var item in result1)
            {
                if (item.CarID == carID)
                {
                    datecmp  = Convert.ToDateTime(item.ReservationStartDate) - datestart;
                    datecmp2 = Convert.ToDateTime(item.ReservationEndDate) - datestart;
                    if (((datecmp.TotalDays) <= 0) && ((datecmp2.TotalDays) > 0))
                    {
                        counta++;
                    }
                }
            }

            if (counta == 0)
            {
                int      a        = 0;
                Customer customer = new Customer();
                customer.CustomerSSN     = int.Parse(form["TC"]);
                customer.CustomerName    = form["CustomerName"];
                customer.CustomerPNumber = form["CustomerPhoneNumber"];
                customer.CustomerAddress = form["CustomerAddress"];
                if (_db.Customers.FirstOrDefault(x => x.CustomerSSN == customer.CustomerSSN) == null)
                {
                    _db.Customers.Add(customer);
                    _db.SaveChanges();
                    a++;
                }

                Reservation Reserv = new Reservation();
                Reserv.CarID                = int.Parse(form["CarID"]);
                Reserv.CustomerSSN          = int.Parse(form["TC"]);
                Reserv.ReservationStartDate = DateTime.Parse(form["Start"]);
                Reserv.ReservationEndDate   = DateTime.Parse(form["End"]);

                Reserv.Car = _db.Cars.FirstOrDefault(x => x.CarID == Reserv.CarID);
                if (a == 0)
                {
                    Reserv.Customer = _db.Customers.FirstOrDefault(x => x.CustomerSSN == customer.CustomerSSN);
                }
                else
                {
                    Reserv.Customer = customer;
                }
                Reserv.ReservationStuation = true;
                List <Reservation> result = _db.Reservations.Where(x => x != null).ToList();
                int i = 1;
                if (result != null)
                {
                    for (int k = 0; k < result.Count; k++)
                    {
                        i = result[k].ReservationID + 1;
                    }
                }
                Reserv.ReservationID = i;

                _db.Reservations.Add(Reserv);
                _db.SaveChanges();

                return(Redirect("/Home"));
            }
            else
            {
                return(Redirect("/Home/Info/" + carID.ToString()));
            }
        }
Ejemplo n.º 9
0
 public bool Create(Product product)
 {
     _contextDatabase.Product.Add(product);
     _contextDatabase.SaveChanges();
     return(true);
 }
Ejemplo n.º 10
0
 public void Save()
 {
     context.SaveChanges();
 }