/// <summary> /// Create a new Lecturer object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="accountId">Initial value of the AccountId property.</param> /// <param name="committeeId">Initial value of the CommitteeId property.</param> public static Lecturer CreateLecturer(global::System.Int32 id, global::System.String name, global::System.Int32 accountId, global::System.Int32 committeeId) { Lecturer lecturer = new Lecturer(); lecturer.Id = id; lecturer.Name = name; lecturer.AccountId = accountId; lecturer.CommitteeId = committeeId; return lecturer; }
public ActionResult AddLecturer(LecturerViewModel lecturer, HttpPostedFileBase file) { if (ModelState.IsValid) { using (new UnitOfWork(_currentContext)) { File photo = null; //save photo if (file != null) { var ticks = DateTime.Now.Ticks; var fileName = String.Format("profile-{0}", ticks) + Path.GetExtension(file.FileName); var absoluteTempPath = Server.MapPath("~/Content/images/uploads/temp/"); var absolutePath = Server.MapPath("~/Content/images/uploads/lecturers/"); var fullVirtualPath = "~/Content/images/uploads/lecturers/" + fileName; //create a temp file first, then compress it FileUploader.UploadFile(file, fileName, absoluteTempPath); var encoder = new ImageEncoder(); encoder.Compress(absoluteTempPath + fileName, absolutePath + fileName, 220, 220); //after compressing deleting original file FileUploader.DeleteFile(absoluteTempPath + fileName); photo = new File() { FileName = fullVirtualPath, FilePurposeId = (int)FilePurposes.Profile }; } //additional info DateTime? birthDate; try { birthDate = DateTime.Parse(lecturer.BirthDate); } catch { birthDate = null; } var lecturerEntry = new Lecturer { Name = lecturer.Name, Description = lecturer.Description, Account = accountRepository.GetByUsername(CurrentUserName), CommitteeId = lecturer.CommitteeId, Profile = new LecturerProfile() { BirthDate = birthDate, Degree = lecturer.Degree, Email = lecturer.Email, Post = lecturer.Post, Room = lecturer.Room, LecturerCategoryId = lecturer.LecturerCategoryId, RecordOfService = lecturer.RecordOfService }, Photo = photo }; lecturersRepository.Add(lecturerEntry); } TempData[Const.ActionResultInfo] = "Профиль преподавателя создан успешно"; return RedirectToAction("Lecturers"); } TempData[Const.ActionErrorInfo] = "Невозможно сохранить профиль преподавателя. Проверьте правильность введенных данных."; return View(); }
/// <summary> /// Deprecated Method for adding a new object to the LecturerSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToLecturerSet(Lecturer lecturer) { base.AddObject("LecturerSet", lecturer); }