public IActionResult GetById(Int32 id) { try { var result = from Shift in _context.Shifts join Position in _context.Positions on Shift.positionId equals Position.Id join Employee in _context.Employees on Shift.EmployeeId equals Employee.Id into fff from asd in fff.DefaultIfEmpty() where Shift.OrganizationId == id select new { Shift, asd, Position }; List <ShiftMergedModel> list = new List <ShiftMergedModel>(); foreach (var item in result) { var title = ""; if (item.Shift.EmployeeId != null) { title = item.asd.FirstName + " " + item.asd.LastName; } TimeSpan from = item.Position.DefaultTime.Value.TimeOfDay; TimeSpan to = item.Position.DefaultTime2.Value.TimeOfDay; ShiftMergedModel shift = new ShiftMergedModel(); shift.Id = item.Shift.Id; shift.EmployeeId = item.Shift.EmployeeId; shift.OrganizationId = item.Shift.OrganizationId; shift.ShiftDate = item.Shift.ShiftDate; shift.SortOrder = item.Shift.SortOrder; shift.PositionId = item.Shift.positionId; shift.PositionName = item.Position.DefaultTime.Value.ToString("HH:mm") + " " + item.Position.Name; shift.Start = item.Shift.ShiftDate + from; shift.End = item.Shift.ShiftDate + to; shift.ResourceId = item.Shift.positionId; shift.Title = title; shift.CanceledBy = item.Shift.CanceledBy; shift.CanceledAt = item.Shift.CanceledAt; shift.IsCanceled = item.Shift.IsCanceled; list.Add(shift); } return(Ok(list)); } catch (System.Exception ex) { return(BadRequest(new { message = "Error is:" + ex.Message })); } }
public ShiftMergedModel GetShift(Shifts myShift) { try { if (myShift.Id == 0) { _context.Shifts.Add(myShift); _context.SaveChanges(); int id = myShift.Id; myShift = _context.Shifts.Where(x => x.Id == id).Single(); } var positions = _context.Positions.Where(x => x.Id == myShift.positionId).Single(); TimeSpan from = positions.DefaultTime.Value.TimeOfDay; TimeSpan to = positions.DefaultTime2.Value.TimeOfDay; ShiftMergedModel shift = new ShiftMergedModel(); shift.Id = myShift.Id; shift.EmployeeId = myShift.EmployeeId; shift.OrganizationId = myShift.OrganizationId; shift.ShiftDate = myShift.ShiftDate; shift.PositionId = myShift.positionId; shift.PositionName = positions.DefaultTime.Value.ToString("HH:mm") + " " + positions.Name; shift.Start = myShift.ShiftDate + from; shift.End = myShift.ShiftDate + to; shift.ResourceId = myShift.positionId; shift.Title = ""; shift.IsCanceled = myShift.IsCanceled; shift.CanceledBy = myShift.CanceledBy; shift.CanceledAt = myShift.CanceledAt; return(shift); } catch (System.Exception) { throw; } }