コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("PropertyId,PropertyNo,City,Street,PostCode,Type,Rooms,Rent,OwnerId,OverseesById")] PropertyForRent propertyForRent)
        {
            if (id != propertyForRent.PropertyId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                int result = await _service.Edit(id, propertyForRent);

                if (result == 0)
                {
                    ViewData["BackController"] = "PropertyForRents";
                    ViewData["BackAction"]     = "Index";
                    ViewData["ErrorMessage"]   = "Entity which you tried to modify doesn't exist anymore";
                    return(View("DbUpdateError"));
                }

                return(RedirectToAction("Index"));
            }
            ViewData["OverseesById"] = new SelectList(_service.Staffs(), "StaffId", "FullName", propertyForRent.OverseesById);
            ViewData["OwnerId"]      = new SelectList(_service.PrivateOwner(), "OwnerId", "FullName", propertyForRent.OwnerId);
            return(View(propertyForRent));
        }
コード例 #2
0
        public async Task <IActionResult> ConcludeContract(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Если эта проперти уже не доступна
            if (_service.GetRentableProperties().FirstOrDefault(p => p.PropertyId == id) == null)
            {
                ViewData["BackController"] = "Contracts";
                ViewData["BackAction"]     = "Index";
                ViewData["ErrorMessage"]   = "This property already has a contract.";
                return(View("DbUpdateError"));
            }

            /* IMPORTANT! */
            //var buildingAgencyContext = _context.PropertyForRent
            //    .Include(c => c.Contract)
            //    .SingleOrDefaultAsync(m => m.PropertyId == id);

            PropertyForRent property = _service.Properties().FirstOrDefault(pfr => pfr.PropertyId == id);

            if (property == null)
            {
                return(NotFound());
            }

            User myUser = await _service.GetUserFromEmail(User.Identity.Name);

            if (myUser == null)
            {
                return(NotFound());
            }

            Client myClient = _service.Clients().FirstOrDefault(x => x.ClientPassportNo == myUser.Passport);

            if (myClient == null)
            {
                return(NotFound());
            }

            //ViewData["clientPassport"] = myUser.Passport;
            ViewData["AllClients"] = new SelectList(_service.Clients(), "ClientId", "ClientPassportNo");
            ViewData["propertyNo"] = property.PropertyNo;

            ViewData["PaymentMeth"] = new SelectList(_service.GetPaymentMethods());

            var contract = new Contract
            {
                PropertyId = property.PropertyId,
                ClientId   = myClient.ClientId,
                Rent       = property.Rent,
                Paid       = false
            };

            return(View(contract));
        }
コード例 #3
0
 public void TC_PropertyForRent()
 {
     try
     {
         test = extent.StartTest("Apply for Property to Rent");
         PropertyForRent ObjPropertyForRent = new PropertyForRent();
         ObjPropertyForRent.ClickPropertyForRent();
         ObjPropertyForRent.SearchMethod();
         ObjPropertyForRent.ApplyForProperty();
         Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Applied for Property For Rent");
     }
     catch (Exception)
     {
         Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, " Error in Apply for Property to Rent");
     }
 }
コード例 #4
0
 public async Task <int> Edit(int id, PropertyForRent property)
 {
     try
     {
         _context.Update(property);
         return(await _context.SaveChangesAsync());
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!PropertyForRentExists(id))
         {
             return(0);
         }
         else
         {
             throw;
         }
     }
 }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("PropertyId,PropertyNo,City,Street,PostCode,Type,Rooms,Rent,OwnerId,OverseesById")] PropertyForRent propertyForRent)
        {
            if (ModelState.IsValid)
            {
                int result = await _service.Create(propertyForRent);

                if (result == 0)
                {
                    ViewData["BackController"] = "PropertyForRents";
                    ViewData["BackAction"]     = "Index";
                    ViewData["ErrorMessage"]   = "Form data has been lost. Database refused your request. Contact sysadmin.";
                    return(View("DbUpdateError"));
                }

                return(RedirectToAction("Index"));
            }
            ViewData["OverseesById"] = new SelectList(_service.Staffs(), "StaffId", "FullName", propertyForRent.OverseesById);
            ViewData["OwnerId"]      = new SelectList(_service.PrivateOwner(), "OwnerId", "FullName", propertyForRent.OwnerId);
            return(View(propertyForRent));
        }
コード例 #6
0
        public async Task <IActionResult> ConcludeContract(int id, [Bind("ContractId,PropertyId,PaymentMethod,Paid,RentStart,RentFinish,Rent,Deposit,ClientId,Duration")] Contract contract)
        {
            if (ModelState.IsValid &&
                contract.RentStart.CompareTo(DateTime.Now.Date) >= 0 &&
                contract.RentFinish.CompareTo(DateTime.Now.Date) > 0)
            {
                // Если эта проперти уже не доступна
                if (_service.GetRentableProperties().FirstOrDefault(p => p.PropertyId == contract.PropertyId) == null)
                {
                    ViewData["BackController"] = "Contracts";
                    ViewData["BackAction"]     = "Index";
                    ViewData["ErrorMessage"]   = "This property already has a contract.";
                    return(View("DbUpdateError"));
                }

                int result = await _service.Create(contract);

                if (result == 0)
                {
                    ViewData["BackController"] = "Contracts";
                    ViewData["BackAction"]     = "Index";
                    ViewData["ErrorMessage"]   = "Form data has been lost. Database refused your request. Contact sysadmin.";
                    return(View("DbUpdateError"));
                }

                return(RedirectToAction("Index"));
            }

            if (!(contract.RentStart.CompareTo(DateTime.Now.Date) >= 0))
            {
                ModelState.AddModelError("RentStart", "Дата начала аренды не должна быть раньше сегодняшнего числа.");
            }
            if (!(contract.RentFinish.CompareTo(DateTime.Now.Date) > 0))
            {
                ModelState.AddModelError("RentFinish", "Дата окончания аренды должна быть позже сегодняшнего числа.");
            }

            PropertyForRent property = _service.Properties().FirstOrDefault(pfr => pfr.PropertyId == id);

            if (property == null)
            {
                return(NotFound());
            }

            User myUser = await _service.GetUserFromEmail(User.Identity.Name);

            if (myUser == null)
            {
                return(NotFound());
            }

            Client myClient = _service.Clients().FirstOrDefault(x => x.ClientPassportNo == myUser.Passport);

            if (myClient == null)
            {
                return(NotFound());
            }

            ViewData["AllClients"]  = new SelectList(_service.Clients(), "ClientId", "ClientPassportNo");
            ViewData["propertyNo"]  = property.PropertyNo;
            ViewData["PaymentMeth"] = new SelectList(_service.GetPaymentMethods());

            return(View(contract));
        }
コード例 #7
0
        public async Task <int> Create(PropertyForRent property)
        {
            _context.Add(property);

            return(await _context.SaveChangesAsync());
        }
 // POST: PropertyForRents/Edit/5
 public async Task <int> Edit(int id, PropertyForRent propertyForRent)
 {
     return(await _repository.Edit(id, propertyForRent));
 }
 public async Task <int> Create(PropertyForRent propertyForRent)
 {
     return(await _repository.Create(propertyForRent));
 }