示例#1
0
        public ActionResult updateApp(int userid, string comment)
        {
            var res = "";

            using (var db = new HaircutterContext()) {
                if (db.Customers.Where(i => i.Id == userid).FirstOrDefault().appointmentsCount > 0)
                {
                    if (string.IsNullOrEmpty(comment))
                    {
                        comment = "";
                    }
                    db.Appointments.Add(new Appointment()
                    {
                        comment         = comment,
                        appointmentDate = DateTime.Now,
                        customerId      = userid
                    });
                    db.Customers.Where(i => i.Id == userid).FirstOrDefault().appointmentsCount -= 1;
                    db.SaveChanges();
                    res = "הצלחה";
                }
                else
                {
                    res = "כישלון מפואר";
                }
            }
            return(Content(res));
        }
示例#2
0
        public ActionResult Index()
        {
            List <Customer> customers = new List <Customer>();

            using (var db = new HaircutterContext()) {
                customers = db.Customers.ToList();
            }

            return(View(customers));
        }
示例#3
0
        public ActionResult AddCustomer(Customer customer)
        {
            using (var db = new HaircutterContext()) {
                db.Customers.Add(customer);
                db.SaveChanges();
            }
            var res = "הלקוח נוסף בהצלחה";

            return(Content(res));
        }
示例#4
0
        public ActionResult DisplayApps(int userid)
        {
            if (userid <= 0)
            {
                userid = 1;
            }
            List <Appointment> appointments = new List <Appointment>();

            using (var db = new HaircutterContext()) {
                appointments = db.Appointments.Where(i => i.customerId == userid).ToList();
            }
            return(View(appointments));
        }
示例#5
0
        public ActionResult deleteSubOrCus(int userId)
        {
            using (var db = new HaircutterContext()) {
                Customer customer = db.Customers.FirstOrDefault(i => i.Id == userId);
                if (customer.isSub)
                {
                    db.Appointments.RemoveRange(customer.Appointments);
                }
                db.Customers.Remove(customer);
                db.SaveChanges();
            }
            var res = "הלקוח נוסף בהצלחה";

            return(Content(res));
        }
示例#6
0
        public ActionResult updateCustomer(int userId, string color)
        {
            using (var db = new HaircutterContext()) {
                var customer = db.Customers.FirstOrDefault(i => i.Id == userId);

                if (!string.IsNullOrEmpty(color))
                {
                    customer.color = color;
                }

                db.SaveChanges();
            }
            var res = "success";

            return(Content(res));
        }
示例#7
0
        public ActionResult updateSub(int userId, string color, int?appToAdd)
        {
            using (var db = new HaircutterContext()) {
                var sub = db.Customers.FirstOrDefault(i => i.Id == userId);
                if (appToAdd != null && appToAdd < 10 && sub.appointmentsCount + appToAdd > 0)
                {
                    sub.appointmentsCount += appToAdd;
                }
                if (!string.IsNullOrEmpty(color))
                {
                    sub.color = color;
                }

                db.SaveChanges();
            }


            var res = "success";

            return(Content(res));
        }