public IHttpActionResult GetDepartment(int id, [FromUri] bool all = true) { var department = db.Departments.FirstOrDefault(x => x.DepartmentId == id); if (department == null) { return(NotFound()); } var doc = department.Doctors.FirstOrDefault(x => x.DoctorType == DoctorType.HeadDepartment); var feedbacks = department.Feedbacks.Select(x => new FeedbackDto { Date = x.Date, Description = x.Description, DepartmentId = x.DepartmentId, FeedbackId = x.FeedbackId, PatientFullName = (x.Patient == null ? "Anonymous" : x.Patient.Name + " " + x.Patient.Surname), PatientURLImage = (x.Patient == null ? Constants.ThisServer + Constants.DefaultPatientImage : Constants.ThisServer + x.Patient.URLImage) }); ShortUserDto HeadDepartment = null; if (doc != null) { HeadDepartment = new ShortUserDto { Surname = doc.Surname, Name = doc.Name, UserId = doc.UserId }; } var a = new DepartmentFullDto { HeadDepartment = HeadDepartment, DepartmentId = department.DepartmentId, Description = department.Description, Name = department.Name, Feedbacks = all == true?feedbacks.ToArray() : feedbacks.Skip(Math.Max(0, department.Feedbacks.Count - 3)).ToArray(), FeedbacksCount = department.Feedbacks.Count, URLImage = Constants.ThisServer + department.URLImage }; return(Ok(a)); }
public bool EditWorker(int userID, ShortUserDto worker) { if (_context.Users.Any(x => (x.UserId == worker.UserID) && x.UserId != userID)) //jezeli id jest juz zajete ale moze byc to co bylo { return(false); } var user = new User { UserId = worker.UserID, Name = worker.Name, Surname = worker.Surname, Password = _context.Users.Where(x => x.UserId == userID).SingleOrDefault().Password }; DeleteWorker(userID); _context.Users.Add(user); _context.SaveChanges(); return(true); }
public bool EditWorker(int userID, ShortUserDto newData) { return(userService.EditWorker(userID, newData)); }
public PlanDetailsDto GetFullPlan(string date) { PlanDetailsDto fullPlan = new PlanDetailsDto(); List <SectorPlanDto> sectorPlans = new List <SectorPlanDto>(); List <SectorDto> sectors = new List <SectorDto>(); var plan = _context.Plans.Where(x => x.Date.Date == DateTime.Parse(date).Date).ToList(); //here is list of users plan: id, userID, date, workName, sectorName, hours if (!plan.Any()) { return(null); } fullPlan.Date = plan.ElementAt(0).Date.ToString(); fullPlan.Hours = plan.ElementAt(0).Hours; foreach (var worker in plan) { //here I create worker from data from list "plan" ShortUserDto user = new ShortUserDto(); SectorDto sector = new SectorDto(); user.UserID = worker.UserID; var nameAndSurname = _context.Users.Where(x => x.UserId == worker.UserID).FirstOrDefault(); user.Name = nameAndSurname.Name; user.Surname = nameAndSurname.Surname; sector.ID = 0; sector.SectorName = worker.Sector; sector.WorkName = worker.WorkName; //if ther's no sectors or sector that worker is assigned hadn't created yet, //then create another sector in "sectors" list and then add it to "sectorPlans" list together with worker bool contains = false; foreach (SectorDto sec in sectors) { if (sec.SectorName == sector.SectorName) { contains = true; } } if (!contains) //!sectors.Contains(sector) doesnt work, i dont know why { sectors.Add(sector); sectorPlans.Add(new SectorPlanDto() { Sector = sector, Workers = new List <ShortUserDto>() { user } }); } //if sector that worker is assigned for is created, then find index of sector that worker is assigned for on the "sectors" list //and add worker to "workers" list in "sectorPlans" list else { int i = 0; int index = 0; foreach (SectorDto sec in sectors) //may be simplified but findIndex does not work, i don't know why { if (sec == sector) { index = i; } i++; } sectorPlans.ElementAt(index).Workers.Add(user); } } fullPlan.Sectors = sectorPlans; return(fullPlan); }