Ejemplo n.º 1
0
        public ValidationAppResult Update(EventTypeViewModel eventTypeViewModel)
        {
            var eventType = Mapping.EventTypeMapper.FromViewModelToDomain(eventTypeViewModel);

            BeginTransaction();

            var result = eventTypeService.Update(eventType);

            if (result.IsValid)
            {
                Commit();
            }

            return(FromDomainToApplicationResult(result));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Convert EventType Object into EventType Entity
 /// </summary>
 ///<param name="model">EventType</param>
 ///<param name="EventTypeEntity">DataAccess.EventType</param>
 ///<returns>DataAccess.EventType</returns>
 public static DataAccess.EventType ToEntity(this EventTypeViewModel model,
                                             DataAccess.EventType entity)
 {
     if (entity.Id == 0)
     {
         entity.CreatedUserId = model.SessionUserId;
         entity.Discriminator = model.Discriminator;
     }
     else
     {
         entity.UpdatedUserId    = model.SessionUserId;
         entity.UpdatedTimestamp = DateTime.Now;
     }
     entity.Name     = model.Name;
     entity.IsActive = model.IsActive;
     return(entity);
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostEventType([FromBody] EventTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var eventType = new EventType
            {
                Name = model.Name
            };

            _context.EventTypes.Add(eventType);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEventType", new { id = eventType.Id }, eventType));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> Put(Guid key, EventTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _eventTypeService.UpdateAsync(model);

                _unitOfWorkAsync.Commit();
                return(Updated(model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 5
0
        public ActionResult Edit(EventTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = Mapper.Map <EventType>(model);

                entity = _eventtypeRepository.Update(entity);

                //_timelineService.RegisterActivity(Realm.BG, ActivityType.LocationUpdated, User.Id);

                Feedback.AddMessageSuccess(EventTypeResources.LocationEditSuccessMessage);

                return(RedirectToAction(nameof(Index), nameof(EventTypeController).RemoveControllerSuffix()));
            }

            model = BuilModel(model);

            return(View("Manager", model));
        }
Ejemplo n.º 6
0
        public EventTypeViewModel GetEventTypeByName(string name)
        {
            EventTypeViewModel eventType = null;

            try
            {
                eventType = (from n in db.EventTypes.Where(x => x.EventTypeName == name)
                             select new EventTypeViewModel
                {
                    EventTypeName = n.EventTypeName,
                    EventTypeId = n.EventTypeId
                }).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(eventType);
        }
Ejemplo n.º 7
0
        public async Task <EventType> AddEventType(EventTypeViewModel eventType)
        {
            EventType itemCollections = null;

            try
            {
                itemCollections = new EventType
                {
                    EventTypeName = eventType.EventTypeName,
                };
                db.EventTypes.Add(itemCollections);
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                //log.Error(ex.Message);
                throw ex;
            }
            return(itemCollections);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create(EventTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var eventType = new EventType()
                {
                    Id           = Guid.NewGuid(),
                    Name         = model.Name,
                    IsDualPlayer = model.IsDualPlayer,
                    SportId      = model.SportId,
                };
                _context.EventTypes.Add(eventType);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { sportId = model.SportId }));
            }
            ViewData["sportId"] = model.SportId;
            return(View(model));
        }
Ejemplo n.º 9
0
        public EventType Insert(EventTypeViewModel model, string CurrentId)
        {
            var find = Queryable().Where(x => x.Name == model.Name && x.Delete == false).FirstOrDefault();

            if (find != null)
            {
                throw new Exception("Loại sự kiện đã tồn tại");
            }
            else
            {
                var data = new EventType();
                data.Name             = model.Name;
                data.CreatDate        = DateTime.Now;
                data.UserAccount      = _userRepository.Find(CurrentId);
                data.Delete           = false;
                data.LastModifiedDate = DateTime.Now;
                //data.UserAccount = _userRepository.Find(HttpContext.Current.User.Identity.GetUserId());
                base.Insert(data);
                return(data);
            }
        }
Ejemplo n.º 10
0
        public ActionResult Edit(
            [Bind(Include = "EventTypeId,Name,NumberOfDaysToWarning,Active")]
            EventTypeViewModel eventTypeViewModel)
        {
            if (ModelState.IsValid)
            {
                var result = eventTypeAppService.Update(eventTypeViewModel);

                if (!result.IsValid)
                {
                    foreach (var validationAppError in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, validationAppError.Message);
                    }
                    return(View(eventTypeViewModel));
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(eventTypeViewModel));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> Create(
            [Bind(Include = "EventTypeId,Name,NumberOfDaysToWarning")]
            EventTypeViewModel eventTypeViewModel)
        {
            if (ModelState.IsValid)
            {
                var result = eventTypeAppService.Add(eventTypeViewModel);
                if (!result.IsValid)
                {
                    foreach (var validationAppError in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, validationAppError.Message);
                    }
                    return(View(eventTypeViewModel));
                }

                // TODO: check if this should be the action to redirect to
                return(RedirectToAction(nameof(Index)));
            }

            return(View(eventTypeViewModel));
        }
Ejemplo n.º 12
0
        public async Task <bool> UpdateEventTypeDetails(EventTypeViewModel eventType)
        {
            bool status    = false;
            var  getRecord = (from r in db.EventTypes.Where(x => x.EventTypeId.Equals(eventType.EventTypeId)) select r).FirstOrDefault();

            if (getRecord != null)
            {
                try
                {
                    getRecord.EventTypeName = eventType.EventTypeName;
                    await db.SaveChangesAsync();

                    status = true;
                }
                catch (Exception ex)
                {
                    status = false;
                    throw ex;
                }
            }
            return(status);
        }
Ejemplo n.º 13
0
        public ActionResult ViewAllEventTypes()
        {
            var eventtypes = new List <EventTypeViewModel>();
            var _companyId = Convert.ToInt32(User.Identity.GetUserId());

            if (_companyId > 0)
            {
                var result = _eventTypeService.GetAllEventTypes(_companyId);
                if (result != null && result.eventTypes.Count != 0)
                {
                    foreach (var obj in result.eventTypes)
                    {
                        var eventtype = new EventTypeViewModel();
                        eventtype.Id          = obj.Id;
                        eventtype.Type        = obj.Type;
                        eventtype.Description = obj.Description;
                        eventtypes.Add(eventtype);
                    }
                }
            }
            return(View(eventtypes));
        }
Ejemplo n.º 14
0
        public async Task <IHttpActionResult> Post(EventTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var stf = await _eventTypeService.InsertAsync(model, GetCurrentUserID());

                _unitOfWorkAsync.Commit();
                var resultObject = new EventPurposeViewModel()
                {
                    ID   = stf.Id,
                    Name = stf.Name,
                };
                return(Created(resultObject));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 15
0
		private void BuildTree()
		{
			RootFilters = new ObservableCollection<EventTypeViewModel>();
			RootFilters.Add(new EventTypeViewModel(JournalSubsystemType.System));
			RootFilters.Add(new EventTypeViewModel(JournalSubsystemType.SKD));
			RootFilters.Add(new EventTypeViewModel(JournalSubsystemType.GK));
			foreach (JournalEventNameType enumValue in Enum.GetValues(typeof(JournalEventNameType)))
				if (enumValue != JournalEventNameType.NULL)
				{
					var eventTypeViewModel = new EventTypeViewModel(enumValue);
					switch (eventTypeViewModel.JournalSubsystemType)
					{
						case JournalSubsystemType.System:
							RootFilters[0].AddChild(eventTypeViewModel);
							break;
						case JournalSubsystemType.SKD:
							RootFilters[1].AddChild(eventTypeViewModel);
							break;
						case JournalSubsystemType.GK:
							RootFilters[2].AddChild(eventTypeViewModel);
							break;
					}
				}
		}
Ejemplo n.º 16
0
        public async Task <IActionResult> Edit(Guid?id, EventTypeViewModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var eventType = await _context.EventTypes.FindAsync(id);

                if (eventType == null)
                {
                    return(NotFound());
                }

                eventType.Name = model.Name;

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { sportId = model.SportId }));
            }
            return(View(model));
        }
Ejemplo n.º 17
0
        public void ValidatorShouldHaveErrorWhenTypeIsInvalid(EventTypeViewModel value)
        {
            ValidationResult result = _validator.Validate(value);

            result.Errors.Should().NotBeEmpty();
        }
Ejemplo n.º 18
0
 public async Task <EventType> InsertAsync(EventTypeViewModel model, string CurrentId)
 {
     return(await Task.Run(() => Insert(model, CurrentId)));
 }