public async Task <ActionResult> AddAssignment(Guid groupId, [FromBody] AddAssignment command)
        {
            command.UserId  = User.GetUserId();
            command.GroupId = groupId;
            await _assignmentService.AddAssignment(command);

            return(Ok());
        }
 public string AddAssignment(Assignment assignment)
 {
     try {
         return(_assignmentService.AddAssignment(assignment));
     } catch (Exception ex) {
         Log.Write(ex);
         throw;
     }
 }
Exemple #3
0
        public async Task <IActionResult> AddAssignment(AddAssignmentDto newAssignment)
        {
            ServiceResponse <List <GetAssignmentDto> > response = await _assignmentService.AddAssignment(newAssignment);

            if (response.Success == false)
            {
                return(BadRequest(response));
            }
            return(Ok(response));
        }
Exemple #4
0
        public async Task <IActionResult> AddAssignment([FromBody] AssignmentRequest request)
        {
            Assignment temp = _mapper.Map <Assignment>(request);

            if (await _assignmentService.AddAssignment(temp))
            {
                return(Ok("Successful"));
            }
            return(BadRequest("Assignment Is Exist"));
        }
 public void Post([FromBody] AssignmentViewModel data)
 {
     if (data.DueDate < DateTime.Now)
     {
         throw new Exception("Wrong date input, date must match format yyyy-MM-dd");
     }
     assignmentService.AddAssignment(new AssignmentModel {
         Laboratory = new LaboratoryModel {
             Id = data.LaboratoryId
         }, Name = data.Name, DueDate = data.DueDate, Description = data.Description
     });
 }
Exemple #6
0
 public IActionResult AddAssignment([FromBody] MvAssignment assignment)
 {
     try
     {
         dynamic jsonString = _assignmentService.AddAssignment(assignment);
         return(Ok(jsonString));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #7
0
 public IActionResult AddAssignment([FromBody] MvAssignment assignment)
 {
     try
     {
         var added = _assignmentService.AddAssignment(assignment);
         if (!added)
         {
             return(BadRequest());
         }
         return(Ok());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public IActionResult AssignmentAdd([FromBody] MvAssignment assignment)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         var data = _assignmentService.AddAssignment(assignment);
         return(Ok(data));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public IActionResult AddAssignment([FromBody] MvAssignment assignment)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         var added = _assignmentService.AddAssignment(assignment);
         if (!added)
         {
             return(BadRequest());
         }
         return(Ok());
     }
     catch (Exception)
     {
         throw;
     }
 }
        public HttpResponseMessage Create([FromBody] AssignmentAPIShortModel assignmentAPIShortModel)
        {
            var assign = _assignmentService.GetByLabAndName(assignmentAPIShortModel.LabNumber, assignmentAPIShortModel.Name);

            if (assign.Laboratory != null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Assignment already created!"));
            }

            else
            if (assignmentAPIShortModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            else
            {
                var att1 = _assignmentAPIShortModel.Map(assignmentAPIShortModel);
                var att  = _assignmentAPIMapper.Map(att1);
                _assignmentService.AddAssignment(att);
                return(Request.CreateResponse(HttpStatusCode.Created, _assignmentAPIMapper.Map(_assignmentAPIShortModel.Map(assignmentAPIShortModel))));
            }
        }
        public IActionResult AddAssignment(NewAssignmentVm model)
        {
            var id = _assignmentService.AddAssignment(model);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> UploadAsync(IFormFile file, AssignmentViewModel avm)
        {
            try
            {
                if (avm != null)
                {
                    //if(avm.TaskId)
                    avm.Description = HtmlEncoder.Default.Encode(avm.Description);
                    avm.FileName    = HtmlEncoder.Default.Encode(avm.FileName);
                    var ip = HttpContext.Connection.RemoteIpAddress;;
                    if (System.IO.Path.GetExtension(file.FileName) == ".pdf" && file.Length < 1048576)
                    {
                        //25 50 44 46 2d >> 37 80 68 70 45 PDF
                        byte[] whitelist = new byte[] { 37, 80, 68, 70, 45 };
                        if (file != null)
                        {
                            var sign = await _userManager.FindByNameAsync(User.Identity.Name);

                            using (var f = file.OpenReadStream())
                            {
                                byte[] buffer = new byte[5]; //how to read an x amount of bytes at 1 go
                                f.Read(buffer, 0, 5);        //offset - how many bytes you would lke the pointer to skip

                                for (int i = 0; i < whitelist.Length; i++)
                                {
                                    if (whitelist[i] == buffer[i])
                                    {
                                    }
                                    else
                                    {
                                        //the file is not acceptable
                                        ModelState.AddModelError("file", "File is not valid and acceptable");
                                        return(View());
                                    }
                                }
                                //...other reading of bytes happening
                                f.Position = 0;
                                //uploading the file
                                string fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                                avm.Path   = fileName;
                                avm.TaskId = taskID;
                                MemoryStream msIn      = new MemoryStream(Encoding.UTF32.GetBytes(fileName));
                                string       signature = Encryption.SignData(msIn, sign.PrivateKey);
                                avm.Signature = signature;
                                string absolutePath = _env.WebRootPath + @"\Files\" + fileName;
                                try
                                {
                                    using (FileStream fsOut = new FileStream(absolutePath, FileMode.CreateNew, FileAccess.Write))
                                    {
                                        // throw new Exception();
                                        f.CopyTo(fsOut);
                                    }
                                    f.Close();
                                }
                                catch (Exception ex)
                                {
                                    //log

                                    _logger.LogError("-->" + User.Identity.Name + " has encountered an error while saving file from this Ip address " + ip + " || " + ex);
                                    return(View("Error", new ErrorViewModel()
                                    {
                                        Message = "Error while saving the file. Try again later"
                                    }));
                                }
                            }
                        }
                        else
                        {
                            TempData["error"] = "Invalid File!";
                            return(View());
                        }
                    }
                    _assignmentService.AddAssignment(avm);
                    TempData["message"] = "Assignment added successfully";
                    ip = HttpContext.Connection.RemoteIpAddress;
                    _logger.LogInformation("-->" + User.Identity.Name + " has successfully saved a file from this Ip address " + ip);
                    return(View());
                }
                else
                {
                    TempData["message"] = "Fill in the form correctly!";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                TempData["error"] = "Could not add assignment!";
                return(View());
            }
        }