示例#1
0
        //to update the data from edit Meeting Form
        public bool UpdateMeetingDetails(int id, MeetingVM meeting)
        {
            try
            {
                bool status = false;
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    var meetingEntity = dc.Meetings.FirstOrDefault(a => a.MeetingId == id);
                    if (meetingEntity == null)
                    {
                        return(status);
                    }
                    else
                    {
                        #region//updating schedule for specific record
                        var scheduleEntity = dc.Schedules.FirstOrDefault(a => a.ScheduleId == meetingEntity.ScheduleId);
                        scheduleEntity.StartTime = meeting.StartTime;
                        scheduleEntity.EndTime   = meeting.EndTime;
                        scheduleEntity.RoomId    = meeting.RoomId;
                        dc.SaveChanges();
                        #endregion

                        #region//updating meeting for specific record
                        meetingEntity.MeetingName = meeting.MeetingName;
                        meetingEntity.Agenda      = meeting.Agenda;
                        //for updating meeting schedule Id is not require cause it is already present in database
                        //for updating meeting User Id is not require cause it is already present in database.()
                        meetingEntity.UpdatedAt = DateTime.Now;
                        dc.SaveChanges();
                        #endregion

                        #region//updating meeting attendance for specific record
                        var meetingAttendeeIdObject = dc.MeetingsAttendees.Where(a => a.MeetingId == id).ToList();
                        foreach (var item in meetingAttendeeIdObject)
                        {
                            dc.MeetingsAttendees.Remove(item);
                            dc.SaveChanges();
                        }

                        foreach (int userid in meeting.MeetingAttendeeId)
                        {
                            MeetingsAttendee attendee = new MeetingsAttendee();
                            attendee.MeetingId = id;
                            attendee.UserId    = userid;
                            dc.MeetingsAttendees.Add(attendee);
                            dc.SaveChanges();
                        }
                        #endregion
                        status = true;
                    }
                }
                return(status);
            }

            catch (Exception)
            {
                return(false);
            }
        }
        public IHttpActionResult PutMeeting(int id, [FromBody] Models.MeetingM meeting)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }
            try
            {
                using (var ctx = new TrainingAndMeetingDBEntities())
                {
                    Meeting      tra             = new Meeting();
                    Schedule     sch             = new Schedule();
                    RoomDetail   rm              = new RoomDetail();
                    MeetingListM mList           = new MeetingListM();                  //object of model class
                    var          data            = db.Meetings.ToList();                //all list of meetings
                    var          existingmeeting = ctx.Meetings.Where(s => s.MeetingId == id)
                                                   .FirstOrDefault <Meeting>();         //get existing meeting details
                    var existingschedule = ctx.Schedules.Where(s => s.ScheduleId == existingmeeting.ScheduleId)
                                           .FirstOrDefault <Schedule>();                // get existing schedule
                    var existingmeetingattendee = ctx.MeetingsAttendees.Where(s => s.MeetingId == existingmeeting.MeetingId)
                                                  .FirstOrDefault <MeetingsAttendee>(); //get existing meeting attendee list
                    if (existingmeeting != null)
                    {
                        existingschedule.StartTime = DateTime.ParseExact(meeting.StartTime, "yyyy-MM-dd HH:mm:ss",
                                                                         System.Globalization.CultureInfo.InvariantCulture);
                        existingschedule.EndTime = DateTime.ParseExact(meeting.EndTime, "yyyy-MM-dd HH:mm:ss",
                                                                       System.Globalization.CultureInfo.InvariantCulture);
                        existingschedule.RoomId = meeting.RoomId;
                        var obj = db.Schedules.Add(sch);
                        ctx.SaveChanges();

                        existingmeeting.MeetingName = meeting.MeetingName;    //add value in training table
                        existingmeeting.Agenda      = meeting.Agenda;
                        // existingmeetingattendee.MeetingId = meeting.MeetingId;
                        var obj1 = db.Meetings.Add(tra);
                        foreach (int userid in meeting.MeetingAttendeeId)
                        {
                            MeetingsAttendee list = new MeetingsAttendee();    //object of model class
                            list.UserId    = userid;
                            list.MeetingId = existingmeeting.MeetingId;
                            ctx.MeetingsAttendees.Add(list);
                            ctx.SaveChanges();
                        }
                        ctx.SaveChanges();
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok(meeting));
        }
示例#3
0
        //to  insert the data from create Meeting form
        public bool InsertMeetingDetails(MeetingVM meeting)
        {
            try
            {
                bool status = false;
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    #region//Creating new schedule record
                    Schedule schedule = new Schedule();
                    schedule.StartTime = meeting.StartTime;
                    schedule.EndTime   = meeting.EndTime;
                    schedule.RoomId    = meeting.RoomId;
                    var obj = dc.Schedules.Add(schedule);
                    dc.SaveChanges();
                    #endregion

                    #region//Creating new meeting record
                    Meeting meetin = new Meeting();
                    meetin.MeetingName = meeting.MeetingName;
                    meetin.Agenda      = meeting.Agenda;
                    meetin.ScheduleId  = obj.ScheduleId;
                    meetin.UserId      = meetin.UserId;
                    meetin.CreatedAt   = meetin.CreatedAt;
                    meetin.UpdatedAt   = meetin.UpdatedAt;
                    var obj1 = dc.Meetings.Add(meetin);
                    dc.SaveChanges();
                    #endregion

                    #region//inserting attendeesId's(user's) into meetingattendee's table
                    foreach (int userid in meeting.MeetingAttendeeId)
                    {
                        MeetingsAttendee attendee = new MeetingsAttendee();
                        attendee.MeetingId = obj1.MeetingId;
                        attendee.UserId    = userid;
                        dc.MeetingsAttendees.Add(attendee);
                        dc.SaveChanges();
                    }
                    #endregion
                    status = true;
                }
                return(status);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 [ResponseType(typeof(Meeting))]                               //post data for craete new tarining
 public IHttpActionResult PostMeeting(Models.MeetingM meeting) //bind training model
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(NotFound());
         }
         Schedule sch = new Schedule();                  //object schedule entity
         sch.StartTime = DateTime.ParseExact(meeting.StartTime, "yyyy-MM-dd HH:mm:ss",
                                             System.Globalization.CultureInfo.InvariantCulture);
         sch.EndTime = DateTime.ParseExact(meeting.EndTime, "yyyy-MM-dd HH:mm:ss",
                                           System.Globalization.CultureInfo.InvariantCulture);
         var obj = db.Schedules.Add(sch);
         sch.RoomId = meeting.RoomId;
         db.SaveChanges();                             //save data in schedule table
         Meeting met = new Meeting();                  //object of Training entity
         met.MeetingName = meeting.MeetingName;
         met.Agenda      = meeting.Agenda;
         met.ScheduleId  = obj.ScheduleId;            //getting Scheduleid from schedule table
         met.CreatedAt   = DateTime.Now;
         met.UpdatedAt   = DateTime.Now;
         met.UserId      = meeting.UserId;
         var obj1 = db.Meetings.Add(met);
         db.Meetings.Add(met);               //save data in meeting db
         db.SaveChanges();
         foreach (int userid in meeting.MeetingAttendeeId)
         {
             MeetingsAttendee mList = new MeetingsAttendee();    //object of model class
             mList.UserId    = userid;
             mList.MeetingId = obj1.MeetingId;
             db.MeetingsAttendees.Add(mList);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
     return(CreatedAtRoute("DefaultApi", new { id = meeting.MeetingId }, meeting));
 }
        public IHttpActionResult DeleteMeeting(int id)
        {
            MeetingsAttendee meetingsAttendee = db.MeetingsAttendees.Where(a => a.MeetingId == id).FirstOrDefault();
            Meeting          meeting          = db.Meetings.Find(id);
            Schedule         schedule         = db.Schedules.Where(a => a.ScheduleId == meeting.ScheduleId).FirstOrDefault();

            try
            {
                if (meeting == null)
                {
                    return(NotFound());
                }
                db.Meetings.Remove(meeting);
                db.Schedules.Remove(schedule);
                db.MeetingsAttendees.Remove(meetingsAttendee);
                db.SaveChanges();

                return(Ok(meeting));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }