Ejemplo n.º 1
0
 private void AssertItemType(ItemTypeDto itemType)
 {
     Assert.That(itemType.Id, Is.Not.Null.Or.Empty);
     Assert.That(itemType.Icon, Is.Not.Null.Or.Empty);
     Assert.That(itemType.Name, Is.Not.Null.Or.Empty);
     Assert.That(itemType.Path, Is.Not.Null.Or.Empty);
     Assert.That(itemType.Slug, Is.Not.Null.Or.Empty);
 }
Ejemplo n.º 2
0
        public ActionResult PostItemType([FromBody] ItemTypeDto itemTypeDto)
        {
            var itemType = new ItemType(itemTypeDto.Code);

            _itemTypeRepository.Save(itemType);

            return(CreatedAtAction(nameof(GetItemType), new { itemTypeCode = itemType.Code }, itemType));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <object> > CreateItemType([FromBody] ItemTypeDto itemTypeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _itemTypeBL.Create(itemTypeDto);

            return(Ok());
        }
Ejemplo n.º 4
0
        public static void UpdateEntityByDto(this ItemType entity, ItemTypeDto dto)
        {
            if (dto == null || entity == null)
            {
                return;
            }

            entity.ItemTypeName = dto.Name;
            entity.ItemNatureId = dto.ItemNatureId;
            entity.Locked       = dto.Locked;
        }
Ejemplo n.º 5
0
        public Task <AlpApiResponse> UpdateItemType([FromBody] ItemTypeDto itemType)
        {
            var sessionToken = HttpContext.Request.Headers["sessiontoken"];

            if (!_accountService.Authorize(sessionToken, new List <RoleType> {
                RoleType.Admin
            }))
            {
                return(Task.FromResult(new AlpApiResponse {
                    Success = false, Message = "Nincs jogosultsága ehhez a művelethez!"
                }));
            }
            return(_itemTypeService.UpdateItemType(itemType));
        }
Ejemplo n.º 6
0
        public async Task Update(ItemTypeDto itemTypeDto)
        {
            var newItemType = _mapper.Map <ItemType>(itemTypeDto);

            try
            {
                await _itemTypeRepository.UpdateAsync(newItemType);
            }
            catch (DbUpdateConcurrencyException)
            {
                return;
            }
            return;
        }
Ejemplo n.º 7
0
        public static ItemType DtoToEntity(this ItemTypeDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new ItemType
            {
                ItemTypeId = dto.Id,
                ItemTypeName = dto.Name,
                ItemNature = dto.ItemNature?.DtoToEntity(),
                ItemNatureId = dto.ItemNatureId,
                Locked = dto.Locked
            });
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <object> > UpdateItemType([FromBody] ItemTypeDto itemTypeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _itemTypeBL.Update(itemTypeDto);
            }
            catch (System.Exception)
            {
                return(StatusCode(500));
            }

            return(Ok());
        }
Ejemplo n.º 9
0
        public async Task <AlpApiResponse <ItemTypeDto> > InsertNewItemType(ItemTypeDto dto)
        {
            var response = new AlpApiResponse <ItemTypeDto>();

            try
            {
                _logger.LogDebug(new
                {
                    action = nameof(InsertNewItemType),
                    dto    = dto?.ToString()
                }.ToString());

                dto.Validate();

                var itemNature = await _context.ItemNature.FirstOrDefaultAsync(itemN => itemN.ItemNatureId == dto.ItemNatureId);

                if (itemNature == null)
                {
                    throw new Exception("A típushoz tartozó eszköz jelleget kötelező megadni!");
                }

                var entity = dto.DtoToEntity();
                entity.ItemNature = null;
                await _context.ItemType.AddAsync(entity);

                await _context.SaveChangesAsync();

                response.Value = entity.EntityToDto();
            }
            catch (Exception e)
            {
                _logger.LogError(new
                {
                    exception             = e,
                    message               = e.Message,
                    innerException        = e,
                    innerExceptionMessage = e.InnerException?.Message
                }.ToString());
                response.Message = e.Message;
                response.Success = false;
            }

            return(response);
        }
Ejemplo n.º 10
0
        public IHttpActionResult TFUpload()
        {
            string[] Levels = new string[] { "Mild", "Normal", "Strong" };

            var    httpRequest  = HttpContext.Current.Request;
            var    form         = httpRequest.Form;
            string CreatedBy    = "";
            string QuestionType = "";

            try
            {
                if (httpRequest.Files.Count > 0)
                {
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFileBase = httpRequest.Files[file];
                        if (postedFileBase != null)
                        {
                            foreach (string key in form.AllKeys)
                            {
                                CreatedBy    = form["CreatedBy"];
                                QuestionType = form["qType"];
                            }

                            string todaysDate    = DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss");
                            string fileName      = postedFileBase.FileName;
                            string fileExtension = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();
                            fileName = HttpContext.Current.Server.MapPath(string.Format("~/Uploads/{0}.{1}", "Import_" + todaysDate, fileExtension));
                            postedFileBase.SaveAs(fileName);

                            byte[] byteArray = File.ReadAllBytes(fileName);
                            using (MemoryStream mem = new MemoryStream())
                            {
                                mem.Write(byteArray, 0, byteArray.Length);
                                using (WordprocessingDocument doc = WordprocessingDocument.Open(mem, true))
                                {
                                    MainDocumentPart    mainPart = doc.MainDocumentPart;
                                    IEnumerable <Table> tables   = mainPart.Document.Descendants <Table>();

                                    var           index        = 0;
                                    string        message      = "";
                                    StringBuilder errorBuilder = new StringBuilder();
                                    errorBuilder.AppendLine("<div class='alert alert-danger'  role='alert'>");

                                    bool flag = false;

                                    foreach (var table in tables)
                                    {
                                        index++;

                                        IEnumerable <TableRow> rows = table.Descendants <TableRow>();
                                        TableRow      QuestionTheme = rows.First();
                                        TableRow      ILOS          = rows.ElementAt(1);
                                        TableRow      Level         = rows.ElementAt(2);
                                        TableRow      Duration      = rows.ElementAt(3);
                                        List <string> correctIlos   = new List <string>();

                                        TableCell QuestionThemeCell    = QuestionTheme.Descendants <TableCell>().ElementAt(1);
                                        TableCell ILOSCell             = ILOS.Descendants <TableCell>().ElementAt(1);
                                        TableCell difficuiltyLevelCell = Level.Descendants <TableCell>().ElementAt(1);
                                        TableCell TimeCell             = Duration.Descendants <TableCell>().ElementAt(1);

                                        TableRow  ET     = rows.ElementAt(4);
                                        TableCell ETCell = ET.Descendants <TableCell>().ElementAt(1);

                                        double expectedTime = 0;
                                        double.TryParse(ETCell.InnerText.Trim(), out expectedTime);

                                        TableRow  ShuffleT     = rows.ElementAt(5);
                                        TableCell ShuffleTCell = ShuffleT.Descendants <TableCell>().ElementAt(1);
                                        bool      shuffle      = ShuffleTCell.InnerText.Trim().Equals("True", StringComparison.OrdinalIgnoreCase) ? true : false;


                                        string        Question  = QuestionThemeCell.InnerText.Trim();
                                        string        DiffLevel = difficuiltyLevelCell.InnerText.Trim();
                                        string        Time      = TimeCell.InnerText.Trim();
                                        List <string> ilos      = new ItemService().StringToList(ILOSCell.InnerText.Trim(), ',');



                                        if (string.IsNullOrEmpty(Question))
                                        {
                                            flag = true;
                                            errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> is empty</p>");
                                        }
                                        if (string.IsNullOrEmpty(DiffLevel))
                                        {
                                            flag = true;
                                            errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> is has no Difficulty Level</p>");
                                        }
                                        if (!Levels.Contains(DiffLevel))
                                        {
                                            flag = true;
                                            errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> difficulty level [" + DiffLevel + "] is wrong</p>");
                                        }
                                        if (string.IsNullOrEmpty(Time))
                                        {
                                            flag = true;
                                            errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> is has no Time</p>");
                                        }
                                        if (!ilos.Any())
                                        {
                                            flag = true;
                                            errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> is has no ILOS</p>");
                                        }
                                        else
                                        {
                                            flag = false;


                                            foreach (var ilo in ilos)
                                            {
                                                ReturnMessage check = new ItemService().CheckILO(ilo);
                                                if (check.Key == 1)
                                                {
                                                    correctIlos.Add(check.ReturnId);
                                                }
                                                else
                                                {
                                                    errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> , " + check + " </p>");
                                                }
                                            }
                                        }


                                        List <KeyValuePair <string, bool> > fileAnswers = new List <KeyValuePair <string, bool> >();

                                        List <AlternativesDto> answers = new List <AlternativesDto>();

                                        for (int i = 4; i < rows.Count(); i++)
                                        {
                                            TableRow row = rows.ElementAt(i);

                                            string converter = row.Descendants <TableCell>().First().InnerText;

                                            if (converter.Contains("MACROBUTTON"))
                                            {
                                                converter = converter.Replace("MACROBUTTON", "").Trim();
                                            }
                                            if (converter.Contains("ProtectForm"))
                                            {
                                                converter = converter.Replace("ProtectForm", "").Trim();
                                            }

                                            fileAnswers.Add(new KeyValuePair <string, bool>(row.Descendants <TableCell>().ElementAt(2).InnerText.Trim(),
                                                                                            converter.Equals("T", StringComparison.OrdinalIgnoreCase) ||
                                                                                            converter.Equals("True", StringComparison.OrdinalIgnoreCase)
                                                                                            ));
                                        }

                                        foreach (var ans in fileAnswers)
                                        {
                                            answers.Add(new AlternativesDto {
                                                Text = ans.Key, Correct = ans.Value
                                            });
                                        }


                                        if (!answers.Where(a => a.Correct == true).Any())
                                        {
                                            flag = true;
                                            errorBuilder.AppendLine("<p>Question in Table No <b>(" + index + ")</b> is has no correct answers<p>");
                                        }



                                        message = errorBuilder.ToString();

                                        if (flag == false)
                                        {
                                            ItemTypeDto Qtype = new ItemTypeDto
                                            {
                                                Id   = QuestionType,
                                                Type = ""
                                            };

                                            foreach (var ilo in correctIlos)
                                            {
                                                QuestionDto qDto = new QuestionDto
                                                {
                                                    Item     = Question,
                                                    Ilo      = ilo,
                                                    UserId   = CreatedBy,
                                                    Duration = Time,
                                                    level    = DiffLevel,
                                                    Type     = Qtype,
                                                    TFStatus = answers.FirstOrDefault(a => a.Correct == true).Text
                                                };

                                                ItemAddDto ido = new ItemAddDto()
                                                {
                                                    Question     = qDto,
                                                    Alternatives = new List <AlternativesDto>()
                                                };

                                                new ItemService().AddItem(ido);
                                            }
                                        }


                                        errorBuilder.AppendLine("</hr>");
                                    }

                                    errorBuilder.AppendLine("</div>");

                                    if (flag == true)
                                    {
                                        return(BadRequest(message));
                                    }

                                    return(Ok());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Ok());
        }
Ejemplo n.º 11
0
 internal ItemType(ItemTypeDto dto)
 {
     Name         = dto.Name;
     Id           = dto.Id;
     CountPerSlot = dto.CountPerSlot;
 }
Ejemplo n.º 12
0
 public async Task Create(ItemTypeDto itemTypeDto)
 {
     itemTypeDto.Id = 0;
     var normalItemType = _mapper.Map <ItemType>(itemTypeDto);
     await _itemTypeRepository.CreateAsync(normalItemType);
 }
Ejemplo n.º 13
0
        private async Task <ItemDto> ProcessTypeToItem(ItemTypeDto itemType)
        {
            var item = await Client.GetItemAsync(itemType.Path);

            return(item);
        }