Esempio n. 1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Esempio n. 2
0
        public async Task <Schedule> GetAsync(int scheduleId)
        {
            var schedule = await _context.Schedules.FindAsync(scheduleId);

            if (schedule != null)
            {
                await _context.Entry(schedule)
                .Collection(i => i.ScheduleElements).LoadAsync();
            }

            return(schedule);
        }
 public ActionResult Edit([Bind(Include = "JobSopId,Title")] JobSop jobSop)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jobSop).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(jobSop));
 }
Esempio n. 4
0
 public ActionResult Edit([Bind(Include = "DepartmentId,Title")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(department));
 }
 public ActionResult Edit(Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(contact));
 }
 public ActionResult Edit([Bind(Include = "ScheduleId,Start,Stop,Comment")] Schedule schedule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(schedule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(schedule));
 }
        public ActionResult Edit(TimeSlot timeslot)
        {
            if (ModelState.IsValid)
            {
                db.Entry(timeslot).State = EntityState.Modified;
                db.SaveChanges();
                return(PartialView("GridData", new TimeSlot[] { timeslot }));
            }

            return(PartialView(timeslot));
        }
Esempio n. 8
0
 public void Update(Schedule schedule)
 {
     // add and delete appointments
     foreach (var appointment in schedule.Appointments)
     {
         if (appointment.State == TrackingState.Added)
         {
             _context.Entry(appointment).State = EntityState.Added;
         }
         if (appointment.State == TrackingState.Modified)
         {
             _context.Entry(appointment).State = EntityState.Modified;
         }
         if (appointment.State == TrackingState.Deleted)
         {
             _context.Entry(appointment).State = EntityState.Deleted;
         }
     }
     _context.SaveChanges();
 }
Esempio n. 9
0
        public ActionResult Edit(Activity activity)
        {
            if (ModelState.IsValid)
            {
                db.Entry(activity).State = EntityState.Modified;
                db.SaveChanges();
                return(PartialView("GridData", new Activity[] { activity }));
            }

            return(PartialView(activity));
        }
Esempio n. 10
0
 public ActionResult Edit([Bind(Include = "JobId,Title,DepartmentId,JobSopId")] Job job)
 {
     if (ModelState.IsValid)
     {
         db.Entry(job).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Title", job.DepartmentId);
     ViewBag.JobSopId     = new SelectList(db.JobSops, "JobSopId", "Title", job.JobSopId);
     return(View(job));
 }
Esempio n. 11
0
 public ActionResult Edit(Station station, int[] TimeSlotIDs)
 {
     if (ModelState.IsValid)
     {
         var availableTimeSlots = new List <TimeSlot>();
         if (TimeSlotIDs != null)
         {
             foreach (var timeSlotID in TimeSlotIDs)
             {
                 availableTimeSlots.Add(db.TimeSlots.Find(timeSlotID));
             }
         }
         db.Stations.Attach(station);
         db.Entry(station).Collection(s => s.AvailableTimeSlots).Load();
         station.AvailableTimeSlots = availableTimeSlots;
         db.Entry(station).State    = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     PrepareTimeSlotCheckBoxes();
     return(View(station));
 }
Esempio n. 12
0
        protected async Task <T> MakePersistent <T>(T entity) where T : Entity
        {
            var entry = Context.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                T foundEntity = Context.Set <T>().Find(entity.Id);
                if (foundEntity == null)
                {
                    entry.State = EntityState.Added;
                }
                else
                {
                    entry = Context.Entry(foundEntity);
                    entry.CurrentValues.SetValues(entity);
                    entry.State = EntityState.Modified;
                }
            }

            try
            {
                await Context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Exception occured! {0}", ex.Message);
                Logger.LogError(ex.StackTrace);
                var innerEx = ex.InnerException;
                while (innerEx != null)
                {
                    Logger.LogError("----------------------------------------");
                    Logger.LogError(innerEx, "Exception occured! {0}", innerEx.Message);
                    Logger.LogError(innerEx.StackTrace);
                    innerEx = innerEx.InnerException;
                }
                throw;
            }
            return(entry.Entity);
        }
Esempio n. 13
0
 public JsonResult Edit(Event e)
 {
     if (ModelState.IsValid)
     {
         db.Entry(e).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(e));
     }
     else
     {
         throw new Exception("Could not model bind event.");
     }
 }
Esempio n. 14
0
 public ActionResult Edit([Bind(Include = "ScheduleDetailId,Comment,Formation,ScheduleId,DepartmentId,JobId,EmployeeId")] ScheduleDetail scheduleDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(scheduleDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Title", scheduleDetail.DepartmentId);
     ViewBag.EmployeeId   = new SelectList(db.Employees, "EmployeeId", "Firstname", scheduleDetail.EmployeeId);
     ViewBag.JobId        = new SelectList(db.Jobs, "JobId", "Title", scheduleDetail.JobId);
     ViewBag.ScheduleId   = new SelectList(db.Schedules, "ScheduleId", "Comment", scheduleDetail.ScheduleId);
     return(View(scheduleDetail));
 }
        public ActionResult Edit(SchedulingConstraint schedulingconstraint)
        {
            if (ModelState.IsValid)
            {
                SchedulingConstraint origConstraint = db.SchedulingConstraints
                                                      .Include(c => c.Group)
                                                      .Include(c => c.GroupType)
                                                      .Include(c => c.Station)
                                                      .Single(c => c.ID == schedulingconstraint.ID);
                db.Entry(origConstraint).CurrentValues.SetValues(schedulingconstraint);
                origConstraint.Group     = db.Groups.Find(schedulingconstraint.Group != null ? schedulingconstraint.Group.ID : -1);
                origConstraint.GroupType = db.GroupTypes.Find(schedulingconstraint.GroupType.ID);
                origConstraint.Station   = db.Stations.Find(schedulingconstraint.Station.ID);
                db.SaveChanges();
                return(PartialView("GridData", new SchedulingConstraint[] { origConstraint }));
            }

            return(PartialEditView(schedulingconstraint));
        }
Esempio n. 16
0
        // TODO: set dispatch status to callback & generate interrupt
        // Only start time & callback info are allowed for updates
        public static void SetCallback(Dispatch ThisDispatch)
        {
            Dispatch      dispatch;
            DbEntityEntry entry;
            IrqHandle     irq;
            DateTime      currentdatetimeutc = DateTime.UtcNow;

            using (SchedulingContext se = new SchedulingContext())
            {
                dispatch = se.Dispatches.Find(ThisDispatch.Id);
                entry    = se.Entry <Dispatch>(dispatch);
                entry.CurrentValues.SetValues(ThisDispatch);

                if (entry.State == System.Data.EntityState.Modified)
                {
                    entry.Property("CreatedDateTimeUtc").CurrentValue = entry.Property("CreatedDateTimeUtc").OriginalValue;
                    dispatch.LastModifiedDateTimeUtc = currentdatetimeutc;

                    irq = new IrqHandle()
                    {
                        ScheduleID = ThisDispatch.ScheduleID,
                        DispatchID = ThisDispatch.Id,
                        Level      = IRQL.Dispatch,
                        TimeStamp  = currentdatetimeutc
                    };
                    se.IrqQueue.Add(irq);

                    // simple strategy to retry only once on concurrency update failure
                    try
                    {
                        se.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        // Update original values from the database
                        entry = ex.Entries.Single();
                        entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                        se.SaveChanges();
                    }
                }
            }
        }
 public ActionResult Edit(Group group)
 {
     if (ModelState.IsValid)
     {
         Group origGroup = db.Groups
                           .Include(g => g.Preference1)
                           .Include(g => g.Preference2)
                           .Include(g => g.Preference3)
                           .Include(g => g.Preference4)
                           .Include(g => g.Preference5)
                           .Single(g => g.ID == group.ID);
         db.Entry(origGroup).CurrentValues.SetValues(group);
         origGroup.Preference1 = db.Stations.Find(group.Preference1.ID);
         origGroup.Preference2 = db.Stations.Find(group.Preference2.ID);
         origGroup.Preference3 = db.Stations.Find(group.Preference3.ID);
         origGroup.Preference4 = db.Stations.Find(group.Preference4.ID);
         origGroup.Preference5 = db.Stations.Find(group.Preference5.ID);
         db.SaveChanges();
         return(PartialView("GridData", new Group[] { origGroup }));
     }
     return(PartialEditView(group));
 }
Esempio n. 18
0
        public async Task <bool> AddOrUpdate(JobDto jobDto, CancellationToken ct = default)
        {
            var existingJobEntity = await context.Jobs
                                    .FirstOrDefaultAsync(j => j.SubscriptionName == jobDto.SubscriptionName && j.JobIdentifier == jobDto.JobIdentifier, ct);

            // Return false if there are no updates to be made
            if (existingJobEntity != null &&
                existingJobEntity.DomainName == jobDto.DomainName &&
                existingJobEntity.IsActive == jobDto.IsActive &&
                existingJobEntity.RepeatEndStrategyId == jobDto.RepeatEndStrategyId &&
                existingJobEntity.RepeatIntervalId == jobDto.RepeatIntervalId &&
                existingJobEntity.StartAt.IsEqualToTheMinute(jobDto.StartAt) &&
                existingJobEntity.EndAt.IsEqualToTheMinute(jobDto.EndAt) &&
                existingJobEntity.CronExpressionOverride == jobDto.CronExpressionOverride &&
                existingJobEntity.RepeatOccurrenceNumber == jobDto.RepeatOccurrenceNumber)
            {
                return(false);
            }

            var updatedJobEntity = Mapping.Mapper.Map <JobDto, Job>(jobDto);

            if (existingJobEntity != null)
            {
                updatedJobEntity.JobId = existingJobEntity.JobId;
                context.Entry(existingJobEntity).State = EntityState.Detached;
                context.Jobs.Update(updatedJobEntity);
            }
            else
            {
                await context.Jobs.AddAsync(updatedJobEntity, ct);
            }

            await context.SaveChangesAsync(ct);

            return(true);
        }