Пример #1
0
        public ActionResult AddService(WorkshopServiceModel viewModel)
        {
            var session = Session["LoginWorkshop"] as SessionModel;

            if (session != null)
            {
                using (var db = new MechAppProjectEntities())
                {
                    var workshopService = new WorkshopService()
                    {
                        WorkshopId        = session.WorkshopId,
                        Title             = viewModel.Title,
                        Description       = viewModel.Description,
                        Price             = viewModel.Price.HasValue ? viewModel.Price.Value : 0,
                        PriceDecimal      = viewModel.PriceDecimal.HasValue ? viewModel.PriceDecimal.Value : 0,
                        DurationInHrs     = viewModel.DurationInHours.HasValue ? viewModel.DurationInHours.Value : 0,
                        DurationInMinutes = viewModel.DurationInMinutes.HasValue ? viewModel.DurationInMinutes.Value : 0
                    };

                    db.WorkshopServices.Add(workshopService);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult YourServices()
        {
            var model   = new List <WorkshopServiceModel>();
            var session = Session["LoginWorkshop"] as SessionModel;

            if (session != null)
            {
                using (var db = new MechAppProjectEntities())
                {
                    var services = db.WorkshopServices.Where(x => x.WorkshopId == session.WorkshopId).ToList();

                    foreach (var workshopService in services)
                    {
                        var workshopServiceModel = new WorkshopServiceModel()
                        {
                            WorkshopId        = session.WorkshopId,
                            Title             = workshopService.Title,
                            Description       = workshopService.Description,
                            Price             = workshopService.Price,
                            PriceDecimal      = workshopService.PriceDecimal,
                            DurationInHours   = workshopService.DurationInHrs,
                            DurationInMinutes = workshopService.DurationInMinutes,
                        };

                        model.Add(workshopServiceModel);
                    }
                }
            }

            return(View(model));
        }
Пример #3
0
        public ActionResult YourServices(string sortOrder, string currentFilter, string searchString, int?page)
        {
            var viewModel = new List <WorkshopServiceModel>();
            var session   = Session["LoginWorkshop"] as SessionModel;

            if (session != null)
            {
                using (var db = new MechAppProjectEntities())
                {
                    var services = db.WorkshopServices.Where(x => x.WorkshopId == session.WorkshopId).ToList();

                    foreach (var workshopService in services)
                    {
                        var workshopServiceModel = new WorkshopServiceModel()
                        {
                            ServiceId         = workshopService.ServiceId,
                            WorkshopId        = session.WorkshopId,
                            Title             = workshopService.Title,
                            Description       = workshopService.Description,
                            Price             = workshopService.Price,
                            PriceDecimal      = workshopService.PriceDecimal,
                            DurationInHours   = workshopService.DurationInHours,
                            DurationInMinutes = workshopService.DurationInMinutes,
                        };

                        viewModel.Add(workshopServiceModel);
                    }
                }
            }

            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var eventsView = from w in viewModel
                             select w;

            if (!String.IsNullOrEmpty(searchString))
            {
                eventsView = eventsView.Where(w => w.Title.Contains(searchString));
            }

            switch (sortOrder)
            {
            case "name_desc":
                eventsView = eventsView.OrderByDescending(w => w.Title);
                break;

            default:      // Name ascending
                eventsView = eventsView.OrderBy(w => w.Title);
                break;
            }

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(eventsView.ToPagedList(pageNumber, pageSize)));
        }