示例#1
0
 public SessionModel(SessionModel m)
 {
     id = m.id;
     startTime = m.startTime;
     endTime = m.endTime;
     bike_id = m.bike_id;
     bikeModel = m.bikeModel;
     lastReport = m.lastReport;
     dangerousZoneId = m.dangerousZoneId;
     dangerousZoneTime = m.dangerousZoneTime;
     normalTime = m.normalTime;
     latitude = m.latitude;
     longitude = m.longitude;
     name = m.name;
     address = m.address;
     paid = m.paid;
     normal_price = m.normal_price;
     normal_vat = m.normal_vat;
     danger_price = m.danger_price;
     danger_vat = m.danger_vat;
 }
        public ActionResult Create(SessionModel m)
        {
            {
                var bike = DataRepository.GetBike(m.bike_id);

                try
                {
                    DataRepository.GetLendersOfUser((Guid)Membership.GetUser().ProviderUserKey).Single(l => l.id == bike.currentLenderId);
                }
                catch
                {
                    ModelState.AddModelError("", "Ezt a kerékpárt Ön nem adhatja ki: " + bike.name);
                    throw new Exception();
                }
            }

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception();
                }

                var invoiceId = DataRepository.CreateSession(m);

                return RedirectToAction("Details", new { id = invoiceId, created_now = true });
            }
            catch
            {
                ViewBag.active_menu_item_id = "menu-btn-invoices";
                return View(m);
            }
        }
        public ActionResult Edit(SessionModel m, string submitButton = "")
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception();
                }

                var invoiceModelToUpdate = DataRepository.GetSession((int)m.id);

                if (invoiceModelToUpdate.paid)
                {
                    ModelState.AddModelError("", "A számla nem módosítható, ha már ki van fizetve!");

                    ViewBag.active_menu_item_id = "menu-btn-invoices";
                    ViewBag.Printers = DataRepository.GetLenders().Where(l => l.printer_ip != null);
                    return View(invoiceModelToUpdate);
                }

                invoiceModelToUpdate.name = m.name;
                invoiceModelToUpdate.address = m.address;

                if ((submitButton == "ForceEndSession") && ((invoiceModelToUpdate.endTime == null) || (invoiceModelToUpdate.endTime == new DateTime())))
                {
                    invoiceModelToUpdate.endTime = DateTime.Now;
                }
                else if ((submitButton == "PaySession") && (!invoiceModelToUpdate.paid))
                {
                    invoiceModelToUpdate.paid = true;
                }

                DataRepository.UpdateSession(invoiceModelToUpdate);

                return RedirectToAction("Index");
            }
            catch
            {
                ViewBag.active_menu_item_id = "menu-btn-invoices";
                return View(DataRepository.GetSession((int)m.id));
            }
        }
示例#4
0
        /// <summary>
        /// Creates a new session
        /// </summary>
        /// <param name="m"></param>
        public static int CreateSession(SessionModel m)
        {
            var db = new BicikliDataClassesDataContext();
            var invoiceToInsert = new Session()
            {
                bike_id = m.bike_id,
                name = m.name,              // user data (name)
                address = m.address,        // user data (address)
                dz_id = null,
                dz_time = 0,
                end_time = null,
                last_report = null,
                latitude = null,
                longitude = null,
                normal_time = 0,
                paid = false,
                start_time = DateTime.Now,
                normal_price = DataRepository.GetNormalUnitPrice(),
                normal_vat = DataRepository.GetNormalVAT(),
                danger_price = DataRepository.GetDangerousUnitPrice(),
                danger_vat = DataRepository.GetDangerousVAT()
            };
            db.Sessions.InsertOnSubmit(invoiceToInsert);
            db.Bikes.Single(b => b.is_active && (b.id == m.bike_id)).current_lender_id = null;
            db.SubmitChanges();

            return invoiceToInsert.id;
        }
示例#5
0
        /// <summary>
        /// Reports a session
        /// </summary>
        /// <param name="m"></param>
        public static void ReportSession(SessionModel m)
        {
            var db = new BicikliDataClassesDataContext();
            var report = db.Sessions.Single(s => s.id == m.id);

            report.dz_id = m.dangerousZoneId;
            report.dz_time = m.dangerousZoneTime;
            report.normal_time = m.normalTime;
            report.last_report = m.lastReport;
            report.latitude = m.latitude;
            report.longitude = m.longitude;

            if (report.end_time != m.endTime)
            {
                report.end_time = m.endTime;
            }

            db.SubmitChanges();
        }
示例#6
0
        /// <summary>
        /// Updates a Session in the database
        /// </summary>
        /// <param name="m"></param>
        public static void UpdateSession(SessionModel m)
        {
            var db = new BicikliDataClassesDataContext();
            var invoiceToUpdate = db.Sessions.Single(s => s.id == m.id);

            if (invoiceToUpdate.name != m.name)
            {
                invoiceToUpdate.address = m.name;
            }
            if (invoiceToUpdate.address != m.address)
            {
                invoiceToUpdate.address = m.address;
            }
            if (invoiceToUpdate.end_time != m.endTime)
            {
                invoiceToUpdate.end_time = m.endTime;
            }
            if (invoiceToUpdate.paid != m.paid)
            {
                invoiceToUpdate.paid = m.paid;
            }
            db.SubmitChanges();
        }