예제 #1
0
        public async Task <ActionResult> Create([Bind(Include = "login,passwordHash,passwordSalt,email,firstName,lastName")] User user)
        {
            if (ModelState.IsValid)
            {
                user = userLogic.GeneratePassword(user);
                db.Users.Add(user);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
예제 #2
0
        public async Task <ActionResult> Create([Bind(Include = "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.Diseases.Add(disease);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(disease));
        }
예제 #3
0
        // GET: Animals/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Animal animal = await db.Animals.FindAsync(id);

            animal.Runway.animalCount = animal.Runway.Animals.Count();
            await db.SaveChangesAsync();

            if (animal == null)
            {
                return(HttpNotFound());
            }
            return(View(animal));
        }
예제 #4
0
        // GET: Foods
        public async Task <ActionResult> Index(string keyword)
        {
            foreach (var item in db.Foods)
            {
                item.requirement = item.Spieces.Select(x => x.appetite * x.howMany / x.Foods.Count()).Sum();
            }
            await db.SaveChangesAsync();

            var foods = db.Foods.ToList();

            if (keyword != null)
            {
                foods           = db.Foods.Where(x => x.name.Contains(keyword) || x.requirement.ToString().Contains(keyword)).ToList();
                ViewBag.keyword = keyword;
            }
            return(View(foods));
        }
예제 #5
0
        public async Task <ActionResult> Create([Bind(Include = "id,shipmentId,creationDate,modificationDate,year,month,sum,approved")] Settlement settlement)
        {
            settlement.creationDate     = DateTime.Now;
            settlement.modificationDate = DateTime.Now;
            settlement.approved         = false;
            do
            {
                settlement.id = new Random().Next().ToString();
            } while (db.Settlements.Where(x => x.id == settlement.id).ToList().Count > 0);

            if (ModelState.IsValid && db.Settlements.Where(x => x.shipmentId == settlement.shipmentId).ToList().Count == 0)
            {
                db.Settlements.Add(settlement);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("shipmentId", "Istnieje już rozliczenie dla tej dostawy");

            ViewBag.shipmentId = settlementLogic.CreateShipmentList();
            return(View(settlement));
        }
예제 #6
0
        // GET: Spieces
        public async Task <ActionResult> Index(string keyword)
        {
            foreach (var item in db.Spieces)
            {
                item.howMany = item.Animals.Where(x => x.spiece == item.id).Count();
            }
            await db.SaveChangesAsync();

            var species = db.Spieces.ToList();

            if (keyword != null)
            {
                species         = db.Spieces.Where(x => x.name.Contains(keyword) || x.howMany.ToString().Contains(keyword) || x.appetite.ToString().Contains(keyword)).ToList();
                ViewBag.keyword = keyword;
            }
            return(View(species));
        }
예제 #7
0
        public async Task <ActionResult> Create([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");
            }
            int id = 0;

            do
            {
                id = new Random().Next();
            } while (db.Shipments.Select(x => x.id).ToList().Contains(id));
            shipment.id = id;
            if (ModelState.IsValid)
            {
                db.Shipments.Add(shipment);
                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.supplierId);
            ViewBag.id           = new SelectList(db.Settlements, "shipmentId", "shipmentId", shipment.id);
            return(View(shipment));
        }
        // GET: ServicePoints
        public async Task <ActionResult> Index(string keyword)
        {
            foreach (var item in db.ServicePoints)
            {
                item.howManyWorkers = item.ServicePointWorkers.Count();
            }
            await db.SaveChangesAsync();

            var servicePoints = db.ServicePoints.ToList();

            if (keyword != null)
            {
                servicePoints   = db.ServicePoints.Where(x => x.name.Contains(keyword) || x.type.Contains(keyword) || x.howManyWorkers.ToString().Contains(keyword) || x.income.ToString().Contains(keyword)).ToList();
                ViewBag.keyword = keyword;
            }

            return(View(servicePoints));
        }
예제 #9
0
        // GET: Runways
        public async Task <ActionResult> Index(string keyword)
        {
            foreach (var item in db.Runways)
            {
                item.animalCount = item.Animals.Count;
            }
            await db.SaveChangesAsync();

            var runways = db.Runways.ToList();

            if (keyword != null)
            {
                runways         = db.Runways.Where(x => x.name.Contains(keyword) || x.area.ToString().Contains(keyword) || x.animalCount.ToString().Contains(keyword)).ToList();
                ViewBag.keyword = keyword;
            }
            return(View(runways));
        }
예제 #10
0
        // GET: Supervisors/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Supervisor supervisor = await db.Supervisors.FindAsync(id);

            foreach (var item in supervisor.Runways)
            {
                item.animalCount = item.Animals.Count();
            }
            await db.SaveChangesAsync();

            if (supervisor == null)
            {
                return(HttpNotFound());
            }
            return(View(supervisor));
        }
        // GET: ServicePointWorkers/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

            foreach (var item in servicePointWorker.ServicePoints)
            {
                item.howManyWorkers = item.ServicePointWorkers.Count();
            }
            await db.SaveChangesAsync();

            if (servicePointWorker == null)
            {
                return(HttpNotFound());
            }
            return(View(servicePointWorker));
        }
예제 #12
0
        public async Task <ActionResult> Create([Bind(Include = "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.animalID).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.DiseaseHistories.Add(diseaseHistory);
                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));
        }