public ResponseWrapper <object> RentEquipment(string userName, string startDate, string endDate, int equipmentId)
        {
            try
            {
                var rentStartTime = DateTime.Parse(startDate);
                var rentEndTime   = DateTime.Parse(endDate);
                var renterId      = userRepository.GetUserByName(userName).userId;
                var rentId        = GetEquipmentRentFreeId();
                var isEquipmentId = equipmentTypeRepository.IsId(equipmentId);
                if (!isEquipmentId)
                {
                    return(new ResponseWrapper <object>("Error 404: No such record", false));
                }
                var renting = new RentingEquipment
                {
                    renterId      = renterId,
                    rentTimeStart = rentStartTime,
                    rentTimeEnd   = rentEndTime,
                    equipmentId   = equipmentId,
                    rentId        = rentId
                };

                equipmentRentRepository.RentEquipment(renting);
                equipmentRentRepository.Save();
                return(new ResponseWrapper <object>("OK", true));
            }
            catch (Exception e)
            {
                return(new ResponseWrapper <object>(e.Message, false));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            RentingEquipment rentingEquipment = db.RentingEquipment.Find(id);

            db.RentingEquipment.Remove(rentingEquipment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "rentId,renterId,equipmentId,rentTimeStart,rentTimeEnd,rentName,rentDescription")] RentingEquipment rentingEquipment)
        {
            if (ModelState.IsValid)
            {
                db.RentingEquipment.Add(rentingEquipment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.equipmentId = new SelectList(db.SailingEquipment, "equipmentId", "equipmentName", rentingEquipment.equipmentId);
            ViewBag.renterId    = new SelectList(db.Users, "userId", "userName", rentingEquipment.renterId);
            return(View(rentingEquipment));
        }
        // GET: RentingEquipments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentingEquipment rentingEquipment = db.RentingEquipment.Find(id);

            if (rentingEquipment == null)
            {
                return(HttpNotFound());
            }
            return(View(rentingEquipment));
        }
        // GET: RentingEquipments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentingEquipment rentingEquipment = db.RentingEquipment.Find(id);

            if (rentingEquipment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.equipmentId = new SelectList(db.SailingEquipment, "equipmentId", "equipmentName", rentingEquipment.equipmentId);
            ViewBag.renterId    = new SelectList(db.Users, "userId", "userName", rentingEquipment.renterId);
            return(View(rentingEquipment));
        }
        public ResponseWrapper <object> UpdateEquipmentRent(int rentId, string userName, string startDate, string endDate, int equipmentId)
        {
            try
            {
                var renting = new RentingEquipment
                {
                    renterId      = userRepository.GetUserByName(userName).userId,
                    rentTimeStart = DateTime.Parse(startDate),
                    rentTimeEnd   = DateTime.Parse(endDate),
                    equipmentId   = equipmentId,
                    rentId        = rentId
                };

                equipmentRentRepository.Update(renting);
                equipmentRentRepository.Save();
                return(new ResponseWrapper <object>("OK", true));
            }
            catch (Exception e)
            {
                return(new ResponseWrapper <object>(e.Message, false));
            }
        }
 public ActionResult Edit([Bind(Include = "rentId,renterId,equipmentId,rentTimeStart,rentTimeEnd,rentName,rentDescription")] RentModel rentingEquipment)
 {
     if (ModelState.IsValid)
     {
         var edited = new RentingEquipment
         {
             rentId          = rentingEquipment.renterId,
             renterId        = rentingEquipment.renterId,
             equipmentId     = rentingEquipment.equipmentId,
             rentName        = rentingEquipment.rentName,
             rentTimeStart   = rentingEquipment.rentTimeStart,
             rentTimeEnd     = rentingEquipment.rentTimeEnd,
             rentDescription = rentingEquipment.rentDescription
         };
         db.Entry(edited).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.equipmentId = new SelectList(db.SailingEquipment, "equipmentId", "equipmentName", rentingEquipment.equipmentId);
     ViewBag.renterId    = new SelectList(db.Users, "userId", "userName", rentingEquipment.renterId);
     return(View(rentingEquipment));
 }