Beispiel #1
0
        public Task Consume(ConsumeContext <SaveData> context)
        {
            SaveData dataToSave = context.Message;

            using (var repoContext = new RepoContext())
            {
                foreach (var repo in context.Message.Repos)
                {
                    var original = repoContext.Repos.FirstOrDefault(r => r.full_name == repo.full_name);

                    if (original == null)
                    {
                        repoContext.Repos.Add(repo);
                    }
                    else
                    {
                        repo.id = original.id;
                        repoContext.Entry(original).CurrentValues.SetValues(repo);
                    }
                }

                repoContext.SaveChanges();
            }

            Console.WriteLine("Repos have been saved with the latest data. Details: ");
            Console.WriteLine("Count: " + dataToSave.Repos.Count);

            return(Task.FromResult(context.Message));
        }
        virtual public IActionResult Put(int id, [FromBody] T value)
        {
            // if the request is bad...
            if (value == null || (value as BaseModel).Id != id)
            {
                return(BadRequest());
            }

            // If the item doesn't exist...
            T item = DbSet.Find(id);

            if (item == null)
            {
                return(NotFound());
            }

            // Swap out the new item for the existing one...
            Context.Entry(item).State = EntityState.Detached;
            DbSet.Attach(value);

            // Update the db with the new item...
            DbSet.Update(value);
            Context.SaveChanges();
            return(Ok());
        }
Beispiel #3
0
 private User DisconnectUser(User user)
 {
     if (user != null)
     {
         _context.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
     }
     return(user);
 }
Beispiel #4
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Url,HtmlUrl,CloneUrl,GitUrl,SshUrl,SvnUrl,MirrorUrl,Name,FullName,Description,Homepage,Language,Private,Fork,ForksCount,WatchersCount,MasterBranch,OpenIssuesCount,PushedAt,CreatedAt,UpdatedAt,HasIssues,HasWiki,HasDownloads")] Repo repo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(repo).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(repo));
        }
        public Meetings GetByID(int Id)
        {
            Meetings meeting = RepoContext.Meetings.FirstOrDefault(x => x.Id == Id);

            meeting.AttendeesIds = RepoContext.AttendeeMeeting.Where(x => x.MeetingId == Id).Select(attendee_meeting => attendee_meeting.AttendeeId).ToList();
            if (meeting != null)
            {
                RepoContext.Entry(meeting).State = EntityState.Detached;
                return(meeting);
            }
            return(null);
        }
        public bool Update(Meetings mtng)
        {
            Meetings oldMeetingdata = GetByID(mtng.Id);

            if (oldMeetingdata != null)
            {
                RepoContext.AttendeeMeeting.RemoveRange(RepoContext.AttendeeMeeting.Where(x => x.MeetingId == oldMeetingdata.Id));
                RepoContext.AttendeeMeeting.AddRange(mtng.AttendeesIds.Select(id => new AttendeeMeeting {
                    AttendeeId = id, MeetingId = mtng.Id
                }));
                oldMeetingdata.Subject    = mtng.Subject;
                oldMeetingdata.UpdateDate = DateTime.Now;
                oldMeetingdata.Agenda     = mtng.Agenda;
                oldMeetingdata.DateTime   = mtng.DateTime;
            }

            RepoContext.Entry(oldMeetingdata).State = EntityState.Modified;
            RepoContext.SaveChanges();

            return(true);
        }