예제 #1
0
        public async Task <ActionResult> EditArea(int areaId, int eventId)
        {
            var data = await _eventService.GetEventInformationAsync(eventId);

            var area = data.Areas.Where(x => x.Id == areaId).FirstOrDefault();

            var model = new EventAreaViewModel
            {
                SeatList = area.Seats.Select(x => new EventSeat
                {
                    State       = x.State,
                    EventAreaId = x.EventAreaId,
                    Id          = x.Id,
                    Number      = x.Number,
                    Row         = x.Row
                }).ToList(),
                CoordX      = area.CoordX,
                CoordY      = area.CoordY,
                Description = area.Description,
                Id          = area.Id,
                Price       = area.Price
            };

            ViewBag.Title  = ProjectResources.EventResource.Edit;
            ViewBag.Action = "EditArea";
            return(PartialView("~/Views/Event/Partial/_EventArea.cshtml", model));
        }
예제 #2
0
        public async Task <ActionResult> CreateArea(EventAreaViewModel model)
        {
            if (model.SeatList == null)
            {
                return(Json(new
                {
                    success = false,
                    errors = new string[] { ProjectResources.ResourceErrors.SeatListError }
                }));
            }

            if (!ModelState.IsValid)
            {
                return(Json(new
                {
                    success = false,
                    errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                             .Select(m => m.ErrorMessage).ToArray()
                }));
            }

            try
            {
                var area = new EventArea
                {
                    CoordX      = model.CoordX,
                    CoordY      = model.CoordY,
                    Description = model.Description,
                    Price       = model.Price,
                    Seats       = model.SeatList.ToArray(),
                    EventId     = model.EventId
                };
                await _eventAreaService.CreateAsync(area);
            }
            catch (FaultException <ServiceValidationFaultDetails> exception)
            {
                string error = string.Empty;

                if (exception.Message.Equals("Seat already exists", StringComparison.OrdinalIgnoreCase))
                {
                    error = ProjectResources.ResourceErrors.SeatExistsError;
                }

                if (exception.Message.Equals("Area description isn't unique", StringComparison.OrdinalIgnoreCase))
                {
                    error = ProjectResources.ResourceErrors.AreaDescriptionError;
                }

                return(Json(new
                {
                    success = false,
                    errors = new string[] { error }
                }));
            }
            catch (FaultException exception)
            {
                return(Json(new
                {
                    success = false,
                    error = exception.Message
                }));
            }

            return(Json(new
            {
                success = true
            }));
        }