public async Task <OverexposureContract> DeleteOverexposureContract(int OverexposureContractId)
        {
            OverexposureContract OverexposureContract = await _OverexposureContracts.FindAsync(OverexposureContractId);

            if (OverexposureContract != null)
            {
                //IQueryable<Invoice> inv = _context.Invoices.Include(i => i.Expense_Invoices).Where(i => i.OverexposureContractId == OverexposureContractId);
                //if (inv != null)
                //{
                //    foreach (Invoice i in inv)
                //    {
                //        //IQueryable<Expense_Invoice> expinv = _context.Expense_Invoices.Where(e => e.InvoiceId == i.InvoiceId);
                //        //var expinv = _context.Expense_Invoices.Where(e => e.InvoiceId == i.InvoiceId);
                //        var expinv = i.Expense_Invoices;
                //        if (expinv != null)
                //        {
                //            foreach (Expense_Invoice e in expinv)
                //            {
                //                _context.Expense_Invoices.Remove(e);
                //            }
                //        }
                //        _context.Invoices.Remove(i);
                //    }
                //}
                _context.Pets.Find(OverexposureContract.PetId).StatusOfPet = "Бездомный";
                _OverexposureContracts.Remove(OverexposureContract);
                _context.Pets.Find(OverexposureContract.PetId);
                _context.SaveChanges();
            }

            return(OverexposureContract);
        }
Beispiel #2
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            OverexposureContract overexposureContract = await UOW.OverexposureContractRepository.GetOverexposureContract(id);

            overexposureContract = await UOW.OverexposureContractRepository.DeleteOverexposureContract(id);

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        // GET: OverexposureContractsAdmin/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            OverexposureContract overexposureContract = await UOW.OverexposureContractRepository.GetOverexposureContract(id);

            if (overexposureContract == null)
            {
                return(HttpNotFound());
            }
            return(View(overexposureContract));
        }
Beispiel #4
0
 public async Task <ActionResult> Edit([Bind(Include = "OverexposureContractId,PetId,DateOverexpStart,DateOverexpEnd,IdUserForOverexp")] OverexposureContract overexposureContract)
 {
     if (overexposureContract != null)
     {
         UOW.OverexposureContractRepository.SaveOverexposureContract(overexposureContract, overexposureContract.IdUserForOverexp);
         return(RedirectToAction("Index"));
     }
     ViewBag.PetId            = new SelectList(UOW.PetRepository.ForOverexposurePets, "PetId", "NickName");
     ViewBag.IdUserForOverexp = new SelectList(UOW.UserRepository.OverexposureUsers, "Id", "Email", overexposureContract.IdUserForOverexp);
     return(View(overexposureContract));
 }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "OverexposureContractId,PetId,DateOverexpStart,DateOverexpEnd")] OverexposureContract overexposureContract)
        {
            string usid = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                UOW.OverexposureContractRepository.SaveOverexposureContract(overexposureContract, usid);
                return(RedirectToAction("ListOverex"));
            }
            ViewBag.PetId = new SelectList(UOW.PetRepository.AllPets, "PetId", "NickName");
            return(View(overexposureContract));
        }
Beispiel #6
0
        // GET: OverexposureContractsAdmin/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            OverexposureContract overexposureContract = await UOW.OverexposureContractRepository.GetOverexposureContract(id);

            if (overexposureContract == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PetId            = new SelectList(UOW.PetRepository.ForOverexposurePets, "PetId", "NickName");
            ViewBag.IdUserForOverexp = new SelectList(UOW.UserRepository.OverexposureUsers, "Id", "Email", overexposureContract.IdUserForOverexp);
            return(View(overexposureContract));
        }
 //
 public void SaveOverexposureContract(OverexposureContract OverexposureContract, string UserId)
 {
     if (OverexposureContract.OverexposureContractId == 0)
     {
         OverexposureContract.DateOverexpStart = DateTime.Now;
         OverexposureContract.ApplicationUser  = _context.Users.Find(OverexposureContract.IdUserForOverexp);
         _OverexposureContracts.Add(OverexposureContract);
         _context.Pets.Find(OverexposureContract.PetId).StatusOfPet = "Передержка";
         _context.SaveChanges();
     }
     else
     {
         _context.Entry(OverexposureContract).State = EntityState.Modified;
         _context.SaveChanges();
     }
 }