Beispiel #1
0
        public ActionResult EditSpecialty(EditSpecialty editSpecialty, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                SpecialtyDTO specialty = new SpecialtyDTO
                {
                    Id           = editSpecialty.Id,
                    Number       = editSpecialty.Number,
                    Name         = editSpecialty.Name,
                    Description  = editSpecialty.Description,
                    FacultyId    = editSpecialty.FacultyId,
                    BudgetPlaces = editSpecialty.BudgetPlaces,
                    TotalPlaces  = editSpecialty.TotalPlaces
                };
                if (image != null)
                {
                    string filePath = "/Content/Image/Specialties/" + specialty.Name + Path.GetExtension(image.FileName);
                    if (editSpecialty.Photo != null)
                    {
                        System.IO.File.Delete(Server.MapPath(filePath));
                    }
                    image.SaveAs(Server.MapPath(filePath));
                    specialty.Photo = filePath;
                }
                else
                {
                    specialty.Photo = editSpecialty.Photo;
                }

                _specialty.Update(specialty);
            }
            return(RedirectToAction("Specialties", new { facultyId = editSpecialty.FacultyId }));
        }
Beispiel #2
0
        public IActionResult UpdateSpecialty([FromBody] SpecialtyRequest request)
        {
            if (request == null)
            {
                return(NotFound());
            }

            var specialty = _mapper.Map <Speciality>(request);
            var result    = _specialtyService.Update(specialty);

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

            return(Ok(specialty));
        }
Beispiel #3
0
        public async Task <IActionResult> UpdateSpecialty([FromBody] Specialty request)
        {
            if (request == null)
            {
                return(NotFound());
            }

            var specialty = _mapper.Map <Specialty>(request);

            var result = await _specialtyService.Update(specialty);

            if (result == null)
            {
                return(NotFound("not found"));
            }

            return(Ok(_mapper.Map <SpecialtyResponse>(result)));
        }
Beispiel #4
0
        public ActionResult Edit(SpecialtyEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Error"));
            }
            var entity = new Specialty
            {
                SpecialtyId = model.SpecialtyId,
                CourseId    = model.CourseId,
                Name        = model.SpecialtyName
            };

            if (entity.SpecialtyId != 0)
            {
                _specialtyService.Update(entity);
                _historyService.Insert(new History
                {
                    Email    = AuthHelper.GetUser(HttpContext).Email,
                    Action   = Action.Update,
                    DateTime = DateTime.Now,
                    Entity   = EntityEnum.Speciality
                });
            }
            else
            {
                _specialtyService.Insert(entity);
                _historyService.Insert(new History
                {
                    Email    = AuthHelper.GetUser(HttpContext).Email,
                    Action   = Action.Create,
                    DateTime = DateTime.Now,
                    Entity   = EntityEnum.Speciality
                });
            }
            _unitOfWork.SaveChanges();

            return(RedirectToAction("Index"));
        }