Example #1
0
        public async Task <IActionResult> UpdateAsync([FromBody] EventTypeDto model)
        {
            if (model == null)
            {
                return(NotFound());
            }

            var currentUser = await _identityService.GetCurrentUser();

            if (currentUser == null)
            {
                return(BadRequest(new { error = "You are not allowed!" }));
            }

            var person = await _identityService.GetPersonByUserId(currentUser.Id);

            if (person == null)
            {
                return(BadRequest(new { error = "Person was not found" }));
            }

            var type = await _eventTypeService.GetEventTypeById(model.Id);

            if (type == null)
            {
                return(BadRequest(new { error = "Selected type was not found" }));
            }

            type.Name    = model.Name;
            type.Deleted = model.Deleted;

            await _eventTypeService.UpdateEventType(type);

            return(Ok());
        }
 public void Add(EventTypeDto eventTypeDto)
 {
     _repository.Add(new EventTypes
     {
         Name = eventTypeDto.Name
     });
     _repository.Commit();
 }
Example #3
0
        private void AddLinksToEventType(EventTypeDto eventTypeDto, ResultExecutingContext context)
        {
            LinkGenerator linkGenerator = context.HttpContext.RequestServices.GetRequiredService <LinkGenerator>();

            eventTypeDto.Links = new List <LinkDto>
            {
                new LinkDto(linkGenerator.GetUriByName(context.HttpContext, "GetCompetitionsByEventType", new { eventTypeId = eventTypeDto.Id }),
                            "competitions",
                            "GET")
            };
        }
Example #4
0
        public void EventTypeControllerPostTest()
        {
            // Arrange
            controller = new EventTypeController(_eventTypeRepository);
            var eventTypeDescription = "Celebration";
            var newEventType = new EventTypeDto() { Description = eventTypeDescription };

            // Act
            var result = controller.Post(newEventType) as ObjectResult;

            // Assert
            Assert.AreEqual(eventTypeDescription, ((EventTypeDto)result.Value).Description);
        }
Example #5
0
        public void EventTypeControllerPutTest()
        {
            // Arrange
            controller = new EventTypeController(_eventTypeRepository);
            var eventTypeDescription = "Celebration changed";
            var eventType = new EventTypeDto() { Id = 1, Description = eventTypeDescription };

            // Act
            var result = controller.Put(1, eventType);

            // Assert
            Assert.IsInstanceOfType(result, typeof(NoContentResult));
            Assert.AreEqual(eventTypeDescription, _eventTypeRepository.GetOne(1).Result.Description);
        }
Example #6
0
        public IActionResult Post([FromBody] EventTypeDto posteEventType)
        {
            if (posteEventType == null)
            {
                ModelState.AddModelError("EventType", "Check all required fields");
                return(BadRequest(ModelState));
            }

            var newEventType = new EventType(posteEventType.Description);

            _eventTypeRepository.Add(newEventType);
            _eventTypeRepository.SaveChanges();

            return(CreatedAtRoute("GetEventType", new { id = newEventType.Id }, Mapper.Map <EventType, EventTypeDto>(newEventType)));
        }
Example #7
0
        public static string ToCustomString(this EventTypeDto eventType)
        {
            switch (eventType)
            {
            case EventTypeDto.AscendedEvent:
                return("ASCENDED_EVENT");

            case EventTypeDto.BuildingKill:
                return("BUILDING_KILL");

            case EventTypeDto.CapturePoint:
                return("CAPTURE_POINT");

            case EventTypeDto.ChampionKill:
                return("CHAMPION_KILL");

            case EventTypeDto.EliteMonsterKill:
                return("ELITE_MONSTER_KILL");

            case EventTypeDto.ItemDestroyed:
                return("ITEM_DESTROYED");

            case EventTypeDto.ItemPurchased:
                return("ITEM_PURCHASED");

            case EventTypeDto.ItemSold:
                return("ITEM_SOLD");

            case EventTypeDto.ItemUndo:
                return("ITEM_UNDO");

            case EventTypeDto.SkillLevelUp:
                return("SKILL_LEVEL_UP");

            case EventTypeDto.WardKill:
                return("WARD_KILL");

            case EventTypeDto.WardPlaced:
                return("WARD_PLACED");

            default:
                return(string.Empty);
            }
        }
Example #8
0
        public IActionResult Put(int id, [FromBody] EventTypeDto updatedEventType)
        {
            if (updatedEventType == null || updatedEventType.Id != id)
            {
                ModelState.AddModelError("EventType", "Check all required fields");
                return(BadRequest());
            }

            var originalEventType = _eventTypeRepository.GetOne(id).Result;

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

            originalEventType.Description = updatedEventType.Description;

            _eventTypeRepository.SaveChanges();

            return(new NoContentResult());
        }
Example #9
0
        public async Task <IActionResult> Create([FromBody] EventTypeDto model)
        {
            var currentUser = await _identityService.GetCurrentUser();

            if (currentUser == null)
            {
                return(BadRequest(new { error = "You are not allowed!" }));
            }

            var person = await _identityService.GetPersonByUserId(currentUser.Id);

            if (person == null)
            {
                return(BadRequest(new { error = "Person was not found" }));
            }

            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

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

            var eventType = new EventType()
            {
                Name    = model.Name,
                Deleted = model.Deleted
            };

            await _eventTypeService.CreateEventType(eventType);

            return(Ok());
        }
        private AccountStatementViewModel[] GetStatementsByEventId(string eventId, IMyMentorRepository repository, EntityDto[] entities, 
            IEnumerable<CouponStatusDto> couponStatuses, EventTypeDto[] eventTypes, 
            IEnumerable<TransactionTypeDto> transactionTypes, IEnumerable<CouponTypeDto> couponTypes, 
            IEnumerable<SupportTypeDto> supportTypes, string nisCurrencySymbol)
        {
            var accountStatementVm = new List<AccountStatementViewModel>();
            var clipStatuses = repository.FindClipStatuses();            
            var purchaseStatuses = repository.FindPurchaseStatues().ToArray();

            Event eventrecord = null;
            eventrecord = Task.Run(() => repository.FindEventById(eventId)).Result;

            if (eventrecord == null)
            {
                return new AccountStatementViewModel[0];
            }

            var eventType = eventTypes.FirstOrDefault(x => x.EventTypeKey == eventrecord.EventType);
            var action = eventType != null ? eventType.GetLocalizedField("EventType") : string.Empty;

            // add event
            AddEvent(entities, nisCurrencySymbol, accountStatementVm, eventrecord, action);

            // add coupons
            AddCoupons(eventId, couponTypes, supportTypes, repository, entities, couponStatuses, accountStatementVm, nisCurrencySymbol);

            IEnumerable<Purchase> purchases = repository.FindPurchasesByEventId(eventId);

            // add account statements
            IEnumerable<AccountStatement> accountStatements =  Task.Run(() => repository.FindAccountStatementsByEventId(eventId)).Result;
            var accountStatementViewModels = 
                GetAccountStatements(
                accountStatements, entities, 
                eventTypes, transactionTypes, 
                couponTypes, supportTypes, 
                couponStatuses, nisCurrencySymbol,
                purchases, clipStatuses, purchaseStatuses);
            accountStatementVm.AddRange(accountStatementViewModels);
            
            // add purchases                       
            foreach (var purchase in purchases)
            {
                accountStatementVm.Add(new AccountStatementViewModel
                {
                    Id = purchase.ObjectId,
                    Type = entities.FindEntityName(EntityKeys.Purchases),                    
                    UserName = purchase.UserKey.GetFullName(Language.CurrentLanguageCode),
                    CreatedAt = purchase.UpdatedAt.HasValue ? purchase.UpdatedAt.Value : DateTime.MinValue,
                    DueDate = purchase.UpdatedAt.HasValue ? purchase.UpdatedAt.Value : DateTime.MinValue,
                    Item = purchase.GetItemName(entities),
                    Status = purchaseStatuses.Single(x=>x.StatusCode.ToLower() == purchase.PurchaseStatusCode.ToLower()).GetLocalizedField("purchaseStatus"),
                    Amount = purchase.GetFormattedPrice(),
                    AmountNis = purchase.GetFormattedPriceNis(),
                    AmountClassName = "azure",
                    Remarks = purchase.GetLocalizedField("purchaseRemarks"),
                    Lesson = GetLessonPurchaseView(purchase.ClipKey, purchases, nisCurrencySymbol, clipStatuses, purchaseStatuses, purchase.Event.ObjectId),
                    Bundle = GetBundlePurchaseView(purchase.BundleKey, purchases, nisCurrencySymbol, clipStatuses, purchaseStatuses,purchase.Event.ObjectId),
                    EventData = GetEventData(purchase.Event),
                    Action = action
                });    
            }
            
            return accountStatementVm.ToArray();
        }