public EventEditViewModel(EventEditDto e, List <EventTypeDto> eventTypes, List <EventSeriesDto> eventSeries)
 {
     Id            = e.Id;
     EventTypeId   = e.EventTypeId;
     EventSeriesId = e?.EventSeriesId ?? 0;
     Title         = e.Title;
     Description   = e.Description;
     //FundCenter = e.FundCenter;
     StartDate              = Convert.ToDateTime(e.StartDate);
     EndDate                = Convert.ToDateTime(e.EndDate);
     RegistrationOpenDate   = Convert.ToDateTime(e.RegStartDate);
     RegistrationClosedDate = Convert.ToDateTime(e.RegEndDate);
     MinRegistrationCount   = e.MinRegs;
     MaxRegistrationCount   = e.MaxRegs;
     AllowStandby           = e.MaxStandByRegs < 0;
     if (e.MaxStandByRegs > 0)
     {
         MaxStandbyRegistrationCount = e.MaxStandByRegs;
     }
     else
     {
         MaxStandbyRegistrationCount = null;
     }
     AddressLine1 = e.Street;
     AddressLine2 = e.Suite;
     City         = e.City;
     State        = e.State;
     Zip          = e.Zip;
     EventTypes   = eventTypes.ConvertAll(x => new SelectListItem {
         Value = x.Id.ToString(), Text = x.Name
     });
     EventSerieses = eventSeries.ConvertAll(x => new SelectListItem {
         Value = x.Id.ToString(), Text = x.Title
     });
 }
Exemple #2
0
        public ServiceResult <string> EditEvent(EventEditDto model)
        {
            var serviceResult = new ServiceResult <string>(true);

            var entity = _context.Events.FirstOrDefault(c => c.Id == model.Id);

            if (entity == null)
            {
                serviceResult.AddError("برنامه با شناسه ارسالی یافت نشد");
            }

            #region validation
            if (string.IsNullOrEmpty(model.Title))
            {
                serviceResult.AddError("عنوان برنامه نمی تواند فاقد مقدار باشد");
            }
            if (!string.IsNullOrEmpty(model.Title) && model.Title.Length > 128)
            {
                serviceResult.AddError("تعداد کاراکترهای عنوان برنامه نمی تواند بیش از 128 کاراکتر باشد".ToPersianNumbers());
            }
            #endregion

            if (model.MultiDay)
            {
                if (!model.StartDate.HasValue)
                {
                    serviceResult.AddError("تاریخ شروع برنامه یا وارد نشده است و یا ساختارش اشتباه می باشد");
                }

                if (!model.EndDate.HasValue)
                {
                    serviceResult.AddError("تاریخ پایان برنامه یا وارد نشده است و یا ساختارش اشتباه می باشد");
                }

                if (model.StartDate.HasValue && model.EndDate.HasValue)
                {
                    if (model.EndDate.Value <= model.StartDate.Value)
                    {
                        serviceResult.AddError("تاریخ پایان برنامه نمی تواند از تاریخ شروع برنامه کمتر باشد");
                    }
                }

                model.Date = null;
                model.Time = null;
            }
            else
            {
                if (!model.Date.HasValue)
                {
                    serviceResult.AddError("تاریخ برنامه یا وارد نشده است و یا ساختارش اشتباه می باشد");
                }
                if (string.IsNullOrEmpty(model.Time))
                {
                    serviceResult.AddError("ساعت برنامه نمی تواند فاقد مقدار باشد");
                }

                model.StartDate = null;
                model.EndDate   = null;
            }

            if (serviceResult.IsSuccess)
            {
                entity.MultiDay    = model.MultiDay;
                entity.Description = model.Description;
                entity.Date        = model.Date;
                entity.EndDate     = model.EndDate;
                entity.StartDate   = model.StartDate;
                entity.Title       = model.Title;
                entity.Time        = model.Time;

                if (!string.IsNullOrEmpty(model.PrimaryPicture))
                {
                    serviceResult.Data    = entity.PrimaryPicture;
                    entity.PrimaryPicture = model.PrimaryPicture;
                }

                _context.Entry(entity).State = EntityState.Modified;
                if (_context.SaveChanges() == 0)
                {
                    serviceResult.AddError("در انجام عملیات خطایی رخ داد");
                }
            }

            return(serviceResult);
        }
Exemple #3
0
        public async Task <ActionResult <EventDto> > EditEvent([FromRoute] string eventId, [FromBody] EventEditDto dto)
        {
            EventEditDtoValidator validator = new EventEditDtoValidator();
            ValidationResult      result    = await validator.ValidateAsync(dto);

            if (result.IsValid)
            {
                var userId = User.Claims
                             .Single(p => p.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;
                var administrator = await _dbContext.Administrators
                                    .AsNoTracking()
                                    .SingleOrDefaultAsync(x => x.ApplicationUserId == userId);

                #region 驗證

                if (!administrator.AdministratorConfirmed)
                {
                    return(Problem(title: "禁止修改", detail: "管理員尚未驗證", statusCode: 403));
                }

                #endregion

                var entity = await _dbContext.Events
                             .SingleOrDefaultAsync(x => x.EventId == eventId);

                if (entity == null)
                {
                    return(NotFound());
                }
                var updateEntity = _mapper.Map(dto, entity);
                _dbContext.Events.Update(updateEntity);
                await _dbContext.SaveChangesAsync();

                var routeValues = new { eventId = updateEntity.EventId };
                var returnDto   = _mapper.Map <EventDto>(updateEntity);
                return(CreatedAtAction(nameof(GetEvent), routeValues, returnDto));
            }
            return(BadRequest(result.Errors));
        }