예제 #1
0
        public async Task <ActionResult> Edit([Bind(Include = "id,shipmentDate,supplierName,amount")] Shipment shipment)
        {
            string supplier = Request.Form["supplierName"];

            try
            {
                shipment.supplierId = db.Suppliers.Where(x => x.name == supplier).FirstOrDefault().id;
            }
            catch
            {
                ModelState.AddModelError("supplierId", "Proszę uzupełnić dostawcę");
            }
            if (shipment.shipmentDate > DateTime.Today)
            {
                ModelState.AddModelError("shipmentDate", "Data nie może być większa od obecnej");
            }
            if (ModelState.IsValid)
            {
                db.Entry(shipment).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.id           = new SelectList(db.Settlements, "shipmentId", "shipmentId", shipment.id);
            ViewBag.supplierName = new SelectList(db.Suppliers, "name", "name", shipment.Supplier.name);
            ViewBag.id           = new SelectList(db.Settlements, "shipmentId", "shipmentId", shipment.id);
            return(View(shipment));
        }
        public async Task <ActionResult> Edit([Bind(Include = "id,firstName,lastName,age,salary,employed")] Supervisor supervisor)
        {
            if (ModelState.IsValid)
            {
                db.Entry(supervisor).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(supervisor));
        }
예제 #3
0
        public async Task <ActionResult> Edit([Bind(Include = "login,passwordHash,passwordSalt,email,firstName,lastName")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                user = userLogic.GeneratePassword(user);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
예제 #4
0
        public async Task <ActionResult> Edit([Bind(Include = "id,shipmentId,creationDate,modificationDate,year,month,sum,approved")] Settlement settlement)
        {
            settlement.modificationDate = DateTime.Now;
            if (ModelState.IsValid && db.Settlements.Where(x => x.shipmentId == settlement.shipmentId && x.id != settlement.id).ToList().Count == 0)
            {
                db.Entry(settlement).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("shipmentId", "Istnieje już rozliczenie dla tej dostawy");
            ViewBag.shipmentId = settlementLogic.CreateShipmentList(settlement.shipmentId.ToString());
            return(View(settlement));
        }
예제 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "id,name,howMany,appetite")] Spiece spiece)
        {
            if (db.Spieces.Any(x => x.name == spiece.name && x.id != spiece.id))
            {
                ModelState.AddModelError("name", "Taki gatunek już istnieje");
            }
            if (ModelState.IsValid)
            {
                db.Entry(spiece).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(spiece));
        }
예제 #6
0
        public async Task <ActionResult> Edit([Bind(Include = "id,name,area,animalCount")] Runway runway)
        {
            if (db.Runways.Any(x => x.name == runway.name && x.id != runway.id))
            {
                ModelState.AddModelError("name", "Taki wybieg już istnieje");
            }
            if (ModelState.IsValid)
            {
                db.Entry(runway).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(runway));
        }
예제 #7
0
        public async Task <ActionResult> Edit([Bind(Include = "id,name,requirement,currentAmount")] Food food)
        {
            if (db.Foods.Any(x => x.name == food.name && x.id != food.id))
            {
                ModelState.AddModelError("name", "Takie jedzenie już istnieje");
            }
            if (ModelState.IsValid)
            {
                db.Entry(food).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(food));
        }
        public async Task <ActionResult> Edit([Bind(Include = "id,firstName,lastName,age,salary,employed")] ServicePointWorker servicePointWorker)
        {
            if (servicePointWorker.employed > DateTime.Today)
            {
                ModelState.AddModelError("employed", "Data nie może być większa od obecnej");
            }
            if (ModelState.IsValid)
            {
                db.Entry(servicePointWorker).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(servicePointWorker));
        }
        public async Task <ActionResult> Edit([Bind(Include = "id,name,howManyWorkers,income,type")] ServicePoint servicePoint)
        {
            if (db.ServicePoints.Any(x => x.name == servicePoint.name && x.id != servicePoint.id))
            {
                ModelState.AddModelError("name", "Taki punkt już istnieje");
            }
            if (ModelState.IsValid)
            {
                db.Entry(servicePoint).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(servicePoint));
        }
예제 #10
0
 public ActionResult Edit([Bind(Include = "id,name")] Supplier supplier)
 {
     if (db.Suppliers.Any(x => x.name == supplier.name && x.id != supplier.id))
     {
         ModelState.AddModelError("name", "Taki dostawca już istnieje");
     }
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
예제 #11
0
        public async Task <ActionResult> Edit([Bind(Include = "id,name")] Disease disease)
        {
            if (db.Diseases.Any(x => x.name == disease.name && x.id != disease.id))
            {
                ModelState.AddModelError("name", "Taka choroba już istnieje");
            }
            if (ModelState.IsValid)
            {
                db.Entry(disease).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(disease));
        }
예제 #12
0
        public async Task <ActionResult> Edit([Bind(Include = "id,age,sex,origin,inZooSince,name")] Animal animal)
        {
            string spiece = Request.Form["spiece"];
            string runway = Request.Form["runway"];

            animal.runwayID = db.Runways.Where(x => x.name == runway).FirstOrDefault().id;
            animal.spiece   = db.Spieces.Where(x => x.name == spiece).FirstOrDefault().id;
            if (animal.inZooSince > DateTime.Today)
            {
                ModelState.AddModelError("inZooSince", "Data nie może być większa od obecnej");
            }
            if (ModelState.IsValid)
            {
                db.Entry(animal).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.runwayID = new SelectList(db.Runways, "name", "name", animal.Runway.name);
            ViewBag.spiece   = new SelectList(db.Spieces, "name", "name", animal.Spiece1.name);
            return(View(animal));
        }
예제 #13
0
 public void Update(T obj)
 {
     table.Attach(obj);
     _context.Entry(obj).State = EntityState.Modified;
     _context.SaveChanges();
 }
예제 #14
0
        public async Task <ActionResult> Edit([Bind(Include = "id,beginDate,endDate")] DiseaseHistory diseaseHistory)
        {
            string disease = Request.Form["diseaseName"];
            string animal  = Request.Form["animalID"];

            diseaseHistory.diseaseId = db.Diseases.Where(x => x.name == disease).FirstOrDefault().id;
            diseaseHistory.animalID  = db.Animals.Where(x => x.name == animal).FirstOrDefault().id;

            if (diseaseHistory.beginDate > DateTime.Today)
            {
                ModelState.AddModelError("beginDate", "Data nie może być większa od obecnej");
            }
            if (diseaseHistory.endDate != null)
            {
                if (diseaseHistory.endDate > DateTime.Today)
                {
                    ModelState.AddModelError("endDate", "Data nie może być większa od obecnej");
                }
                else if (diseaseHistory.endDate < diseaseHistory.beginDate)
                {
                    ModelState.AddModelError("endDate", "Data zakończenianie musi być większa od daty rozpoczęcia");
                }
            }
            if (db.DiseaseHistories.Any(x => x.beginDate == diseaseHistory.beginDate &&
                                        x.animalID == diseaseHistory.animalID &&
                                        x.diseaseId == diseaseHistory.diseaseId &&
                                        x.id != diseaseHistory.id))
            {
                ModelState.AddModelError("beginDate", "Wpis z takimi parametrami już istnieje");
                ModelState.AddModelError("animalID", "Wpis z takimi parametrami już istnieje");
                ModelState.AddModelError("diseaseId", "Wpis z takimi parametrami już istnieje");
            }
            Animal   dbAnimal  = db.Animals.Where(x => x.id == diseaseHistory.id).FirstOrDefault();;
            TimeSpan animalAge = new TimeSpan(365 * dbAnimal.age, 0, 0, 0);
            DateTime birth     = DateTime.Today;

            try
            {
                birth = DateTime.Today - animalAge;
            } catch (Exception e)
            {
                ModelState.AddModelError("beginDate", "Zwierzę nie może zachorować zanim się urodziło");
            };


            if (diseaseHistory.beginDate < birth)
            {
                ModelState.AddModelError("beginDate", "Zwierzę nie może zachorować zanim się urodziło");
            }
            if (db.DiseaseHistories.
                Where(x => x.animalID == diseaseHistory.animalID &&
                      x.diseaseId == diseaseHistory.diseaseId &&
                      (x.endDate == null || x.endDate > diseaseHistory.beginDate) &&
                      x.id != diseaseHistory.id).Any())
            {
                ModelState.AddModelError("beginDate", "Zwierzę nie morze dwa razy zachorować na tę samą chorobę!");
                ModelState.AddModelError("animalID", "Zwierzę nie morze dwa razy zachorować na tę samą chorobę!");
                ModelState.AddModelError("diseaseId", "Zwierzę nie morze dwa razy zachorować na tę samą chorobę!");
            }
            if (ModelState.IsValid)
            {
                db.Entry(diseaseHistory).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.animalID    = new SelectList(db.Animals, "name", "name");
            ViewBag.diseaseName = new SelectList(db.Diseases, "name", "name");
            return(View(diseaseHistory));
        }