示例#1
0
        public async Task <ItemGetDto> AddUserAsync(ItemAddDto itemAddDto)
        {
            var item        = _mapper.Map <Item>(itemAddDto);
            var createdItem = await _itemRepository.AddItemAsync(item);

            throw new NotImplementedException();
        }
示例#2
0
 public async Task <DResult <int> > AddItem([FromBody] ItemAddDto addItem)
 {
     try
     {
         return(DResult.Succ(businessItem.AddItem(addItem)));
     }
     catch (Exception ex) {
         Logger.Error(ex.ToString());
         return(DResult.Error <int>(ex.Message, 500));
     }
 }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemAdd"></param>
        /// <returns></returns>
        public int AddItem(ItemAddDto itemAdd)
        {
            TItem item = new TItem
            {
                Id              = IdentityHelper.NewSequentialGuid().ToString("N"),
                Name            = itemAdd.Name,
                SystemId        = itemAdd.SystemId,
                CreateTime      = DateTime.Now,
                SystemJsonItem  = "{}",
                Status          = true,
                FrontSystemName = itemAdd.FrontSystemName,
                FrontSystemCode = itemAdd.FrontSystemCode
            };

            return(IocUnity.Get <RepositoryItem>().Insert(item));
        }
示例#4
0
        public IHttpActionResult AddItem([FromBody] ItemAddDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Model"));
            }

            if (model.Alternatives.Count != 0)
            {
                var correct = model.Alternatives.Where(a => a.Correct == true).ToList();
                if (!correct.Any())
                {
                    return(BadRequest("Please check at leastes on correct answer"));
                }
            }

            var result = new ItemService().AddItem(model);

            return(Ok(result));
        }
示例#5
0
        public async Task <ActionResult> AddItem(ItemAddDto itemAddDto)
        {
            try
            {
                var item = _mapper.Map <Item>(itemAddDto);
                if (item == null)
                {
                    return(BadRequest());
                }

                var createdUser = await _itemRepository.AddItemAsync(item);

                return(CreatedAtAction(nameof(GetItem), new { Id = createdUser.Id },
                                       createdUser));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Erorr adding data to the database"));
            }
        }
示例#6
0
        public async Task <ActionResult <Item> > UpdateItem(int Id, ItemAddDto itemAddDto)
        {
            try
            {
                var itemToUpdate = await _itemRepository.GetItemAsync(Id);

                if (itemToUpdate == null)
                {
                    return(NotFound($"User with Id={Id} not found"));
                }

                _mapper.Map(itemAddDto, itemToUpdate);
                await _itemRepository.UpdateItemAsync(itemToUpdate);

                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Erorr updating data"));
            }
        }
示例#7
0
        public ReturnMessage AddItem(ItemAddDto model)
        {
            string iquery = "";


            if (model.Question.Ilo != "")
            {
                iquery = $"EXECUTE SP_CreateCLassifiedItem N'{model.Question.Item}','{model.Question.Type.Id}','{model.Question.Duration}','{model.Question.UserId}','{model.Question.level}','{model.Question.Ilo}'";
            }
            else
            {
                iquery = $"EXECUTE SP_CreateUnCLassifiedItem N'{model.Question.Item}','{model.Question.Type.Id}','{model.Question.Duration}','{model.Question.UserId}','{model.Question.level}'";
            }
            var item = _db.Database.SqlQuery <string>(iquery).FirstOrDefault();


            ReturnMessage ans = new ReturnMessage();

            if (model.Alternatives.Count == 0)
            {
                string aquery = $"EXECUTE SP_CreateTFAlternative N'{item}','{model.Question.TFStatus}'";
                ans = _db.Database.SqlQuery <ReturnMessage>(aquery).FirstOrDefault();
            }
            else
            {
                foreach (var val in model.Alternatives)
                {
                    string aquery = $"EXECUTE SP_CreateAnswerAlternative N'{item}','{val.Text}','{val.Correct}'";
                    ans = _db.Database.SqlQuery <ReturnMessage>(aquery).FirstOrDefault();
                }
            }



            return(ans);
        }
示例#8
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());
        }