public ActionResult AddUser(string LastName, string FirstName, string Otchectvo, string Position, string Grade, HttpPostedFileBase Foto, int?Room, int?idRoom) { Врач doctors = new Врач(); doctors.Фамилия = LastName.TrimEnd(); doctors.Имя = FirstName.TrimEnd(); doctors.Отчество = Otchectvo.TrimEnd(); doctors.Должность = Position.TrimEnd(); doctors.Квалификация = Grade.TrimEnd(); doctors.Готовность = true; Кабинет room = db.Кабинет.Find(idRoom); if (Foto != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(Foto.InputStream)) { imageData = binaryReader.ReadBytes(Foto.ContentLength); } doctors.Фото = imageData; } db.Врач.Add(doctors); room.Врач.Add(doctors); db.SaveChanges(); ViewBag.IdRoom = idRoom; ViewBag.IdDoctor = doctors.Id_doc; return(View("SelectMode")); }
public int AddDoctor([FromBody] DoctorDto dto) { if (dto == null) { return(0); } Врач doc = new Врач() { ВнешнийХэш = dto.Hash, }; int?userId = dto.UserId; if (userId == null) { userId = new UserController().AddUser(dto.User); } doc.Пользователь = db.GetFromDatabase <Пользователь>(x => x.Id == userId).FirstOrDefault(); if (string.IsNullOrEmpty(doc.ВнешнийХэш)) { doc.ВнешнийХэш = HashHelper.GetHashForNewEntity(doc); } db.Insert(doc); return(doc.Id); }
public DoctorDto(Врач doc) { if (doc == null) { return; } this.Hash = doc.ВнешнийХэш; this.UserId = doc.Пользователь?.Id; if (doc.Пользователь != null) { this.User = new UserDto(doc.Пользователь); } }