Пример #1
0
        public ActionResult CreateSpecialty(CreateSpecialty createSpecialty, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                SpecialtyDTO specialty = new SpecialtyDTO
                {
                    Number       = createSpecialty.Number,
                    Name         = createSpecialty.Name,
                    BudgetPlaces = createSpecialty.BudgetPlaces,
                    TotalPlaces  = createSpecialty.TotalPlaces,
                    Description  = createSpecialty.Description,
                    FacultyId    = createSpecialty.FacultyId
                };
                if (image != null)
                {
                    string filePath = "/Content/Image/Specialties/" + specialty.Name + Path.GetExtension(image.FileName);
                    image.SaveAs(Server.MapPath(filePath));
                    specialty.Photo = filePath;
                }

                _specialty.Create(specialty);
            }

            return(View(new CreateSpecialty {
                FacultyId = createSpecialty.FacultyId
            }));
        }
        public ActionResult Create(CreateSpecialty createSpecialty)
        {
            if (this.ModelState.IsValid)
            {
                var adminId = this.User.Identity.GetUserId();

                var specialty = new Specialty()
                {
                    Name            = createSpecialty.Name,
                    Description     = createSpecialty.Description,
                    Eqd             = createSpecialty.Eqd,
                    FormOfEducation = createSpecialty.FormOfEducation,
                    SubDepartmentId = createSpecialty.SubDepartmentId,
                    AdminId         = adminId
                };

                using (var db = new SpecialtySelectorDbContext())
                {
                    db.Specialties.Add(specialty);
                    db.SaveChanges();

                    var subDepartments = db.SubDepartments.ToList();
                    ViewBag.SubDepartments = subDepartments;

                    return(RedirectToAction("Details", new { id = specialty.Id }));
                }
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var subDepartments = db.SubDepartments.ToList();

                ViewBag.SubDepartments = subDepartments;

                return(View(createSpecialty));
            }
        }