Exemplo n.º 1
0
        public ActionResult AddMaterialInSection(HttpPostedFileBase file, Material model)
        {
            var    section = sectionService.GetSectionById(model.SeksioniId);
            string uid     = User.Identity.GetUserId();

            //vetem instruktori i kursit perkates qe permban seksionin ka te drejte te shtoje materiale
            if (section == null || !courseService.CanUserModifyCourseLevelsAndTypes(uid, (int)section.KursiId))
            {
                return(HttpNotFound());
            }
            if (file != null)
            {
                string error = ValidateFile(file, model.SeksioniId);
                if (!string.IsNullOrEmpty(error))
                {
                    ModelState.AddModelError("err", error);
                }
            }
            else
            {
                ModelState.AddModelError("err", "Zgjidhni nje file.");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    RuajFile(file, model.SeksioniId);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("err", "Nuk u ruajt file ne disk, provo perseri");
                }
                Material newMaterial = new Material()
                {
                    Titulli    = model.Titulli,
                    Pershkrimi = model.Pershkrimi,
                    Filename   = Path.GetFileName(file.FileName),
                    SeksioniId = model.SeksioniId
                };
                if (mService.CreateMaterial(newMaterial))
                {
                    return(RedirectToAction("MaterialsOfSection", new { id = model.SeksioniId }));
                }
                else
                {
                    ModelState.AddModelError("err", "Nje material me te njetin titull tashme ekziston. Julutem zgjidhni nje titull tjeter per materialin tuaj.");
                }
            }
            ViewBag.SeksionId = section.Id;
            ViewBag.Kursi     = section.Kursi.Emri;
            ViewBag.KursId    = section.Kursi.KursId;
            ViewBag.Niveli    = section.Niveli.Emri;
            ViewBag.NivelId   = section.Niveli.Id;
            ViewBag.Tipi      = section.Tipi.Tipi;
            return(View(model));
        }
Exemplo n.º 2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _service.CreateMaterial(Material);

            return(RedirectToPage("Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateMaterial([FromBody] MaterialCreateDto material)
        {
            if (material == null)
            {
                _logger.LogError("Material object sent from client is null");
                return(BadRequest("Material object is null"));
            }
            var materialEntity = _mapper.Map <Material>(material);
            await _service.CreateMaterial(materialEntity);

            return(CreatedAtRoute("MaterialById", new { id = materialEntity.MaterialId }, materialEntity));
        }
Exemplo n.º 4
0
        public ActionResult AddMaterial([FromBody] MaterialModel material)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _logger.LogInformation("Adding Material");
            var newMaterial         = MaterialMapper.SerializeMaterialModel(material);
            var newMaterialResponse = _materialService.CreateMaterial(newMaterial);

            return(Ok(newMaterialResponse));
        }
Exemplo n.º 5
0
        public IActionResult UploadMaterial([FromBody] MaterialDto material)
        {
            var creationResult = _materialService.CreateMaterial(material.Name, material.IsVisible, material.TypeOfPhase, material.MaterialFunction.MinTemperature, material.MaterialFunction.MaxTemperature);

            if (creationResult.errorMessages.Any())
            {
                return(UnprocessableEntity(creationResult.errorMessages));
            }
            else
            {
                var materialDto = creationResult.material.MapToMaterialDto();
                return(Ok(materialDto));
            }
        }
Exemplo n.º 6
0
        public void CreateMaterial(int ssn, int isbn, string library, string typeName, string approach, bool passing)
        {
            //Arrange
            Setup(approach);
            string author = "TestAuthor", description = "TestDescription", title = "testTitle";
            int    quantity = 2;

            //Act
            bool result =
                _materialService.CreateMaterial(ssn, isbn.ToString(), library, author, description, title, typeName, quantity);

            //Assert
            Assert.IsTrue(result.Equals(passing));
        }
Exemplo n.º 7
0
 public JsonResult Add()
 {
     for (int i = 0; i != Request.Files.Count; i++)
     {
         HttpPostedFileBase file     = Request.Files[i];
         byte[]             fileByte = new byte[file.ContentLength];
         file.InputStream.Read(fileByte, 0, file.ContentLength);
         MaterialEntity material = new MaterialEntity()
         {
             Content     = fileByte,
             FileName    = Path.GetFileName(file.FileName),
             Description = ""
         };
         materialService.CreateMaterial(material);
     }
     return(Json("Material has been added"));
 }