public async Task <ActionResult <Schedule> > PostWorplaceSchedule(dtoWorkplaceSchedule wpSchedule) { if (wpSchedule.ScheduleId == 0) { if (ModelState.IsValid) { if (WorkspaceIsMine(wpSchedule.WorkplaceId) == false) { return(NotFound()); } Schedule myNewschedule = new Schedule(); myNewschedule.CreatedDate = DateTime.Now; myNewschedule.CreatedUserID = _CurrentUserID(); myNewschedule.EventsJson = wpSchedule.calEvents; myNewschedule.Type = (long)wpSchedule.Type; WorkplaceSchedule wps = new WorkplaceSchedule(); wps.WorkplaceId = wpSchedule.WorkplaceId; wps.Schedule = myNewschedule; _context.WorkplaceSchedules.Add(wps); try { await _context.SaveChangesAsync(); } catch (Exception ex) { throw; } } } else { if (ScheduleIsMine(wpSchedule.WorkplaceId, wpSchedule.ScheduleId) == false) { return(NotFound()); } var Scheduleindb = _context.Schedules.Single(c => c.Id == wpSchedule.ScheduleId); Scheduleindb.UpdatedUserID = _CurrentUserID(); Scheduleindb.UpdatedDate = DateTime.Now; Scheduleindb.EventsJson = wpSchedule.calEvents; //Scheduleindb.Active = Schedule.Active; //Scheduleindb.MondayStart = Schedule.MondayStart; //Scheduleindb.MondayEnd = Schedule.MondayEnd; //Scheduleindb.TuesdayStart = Schedule.TuesdayStart; //Scheduleindb.TuesdayEnd = Schedule.TuesdayEnd; //Scheduleindb.WednesdayStart = Schedule.WednesdayStart; //Scheduleindb.WednesdayEnd = Schedule.WednesdayEnd; //Scheduleindb.ThursdayStart = Schedule.ThursdayStart; //Scheduleindb.ThursdayEnd = Schedule.ThursdayEnd; //Scheduleindb.FridayStart = Schedule.FridayStart; //Scheduleindb.FridayEnd = Schedule.FridayEnd; //Scheduleindb.SaturdayStart = Schedule.SaturdayStart; //Scheduleindb.SaturdayEnd = Schedule.SaturdayEnd; //Scheduleindb.SundayStart = Schedule.SundayStart; //Scheduleindb.SundayEnd = Schedule.SundayEnd; //var utcDate = Schedule.SundayStart.ToUniversalTime(); _context.Entry(Scheduleindb).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!ScheduleExists(wpSchedule.ScheduleId)) { return(NotFound()); } else { throw; } } catch (Exception ex) { throw; } } return(Json("OK")); }
public async Task <ActionResult <Schedule> > SaveWorplaceScheduleExceptions(string date, dtoWorkplaceSchedule wpSchedule) { //save schedule Exceptions for a given day //delete them first if (WorkspaceIsMine(wpSchedule.WorkplaceId)) { _context.Database.ExecuteSqlRaw("DELETE FROM [WorkplaceScheduleExceptions] where WorkplaceId=@WorkplaceId and [Date]=@date", new SqlParameter("@WorkplaceId", wpSchedule.WorkplaceId.ToString()), new SqlParameter("@date", date)); WorkplaceScheduleException myWSE = new WorkplaceScheduleException(); myWSE.CreatedDate = DateTime.Now; myWSE.CreatedUserID = _CurrentUserID(); myWSE.WorkplaceId = wpSchedule.WorkplaceId; myWSE.Date = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture); myWSE.EventsJson = wpSchedule.calEvents; _context.WorkplaceScheduleExceptions.Add(myWSE); try { await _context.SaveChangesAsync(); } catch (Exception ex) { throw; } } return(Json("OK")); }