//to insert the data from create training form
        public bool InsertTrainingDetails(TrainingVM trainer)
        {
            try
            {
                bool status = false;
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    Schedule schedule = new Schedule();
                    schedule.StartTime = trainer.StartTime;
                    schedule.EndTime   = trainer.EndTime;
                    schedule.RoomId    = trainer.RoomId;
                    var obj = dc.Schedules.Add(schedule);
                    dc.SaveChanges();

                    Training traine = new Training();
                    traine.Topic       = trainer.Topic;
                    traine.Description = trainer.Description;
                    traine.ScheduleId  = obj.ScheduleId;
                    traine.UserId      = trainer.UserId;
                    traine.CreatedAt   = DateTime.Now;
                    traine.UpdatedAt   = DateTime.Now;
                    dc.Trainings.Add(traine);
                    dc.SaveChanges();
                    status = true;
                }
                return(status);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 //to delete the specific training
 public bool DeleteTrainingDetails(int id)
 {
     try
     {
         bool status = false;
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             var trainerEntity = dc.Trainings.FirstOrDefault(a => a.TrainingId == id);
             if (trainerEntity == null)
             {
                 return(status);
             }
             else
             {
                 var scheduleEntity = dc.Schedules.FirstOrDefault(a => a.ScheduleId == trainerEntity.ScheduleId);
                 dc.Schedules.Remove(scheduleEntity);
                 dc.SaveChanges();
                 //dc.Trainings.Remove(trainerEntity);
                 trainerEntity.DeletedAt = DateTime.Now;
                 dc.SaveChanges();
                 status = true;
                 return(status);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #3
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);
            }
        }
Exemple #4
0
        public bool InsertRegistrationInfo(UserCredentialsVM userCredentials)
        {
            try
            {
                bool status = false;
                #region//Save Data To Database
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    User user = new User();
                    user.FirstName = userCredentials.FirstName;
                    user.LastName  = userCredentials.LastName;
                    user.IsActive  = true;
                    user.RoleId    = 1;
                    user.CreatedAt = DateTime.Now;
                    user.UpdatedAt = DateTime.Now;
                    var obj = dc.Users.Add(user);
                    dc.SaveChanges();

                    #region//Taking data fromviewmodel and assigning to database entity
                    UserCredential credentials = new UserCredential();
                    credentials.Email = userCredentials.Email;


                    #region//Generate Activation
                    credentials.ActivationCode = Guid.NewGuid();
                    #endregion

                    #region//Password Hashing
                    credentials.Password = Crypto.Hash(userCredentials.Password);
                    #endregion

                    credentials.IsActivated     = true;
                    credentials.IsEmailVerified = false;
                    credentials.UserId          = obj.UserId;
                    dc.UserCredentials.Add(credentials);
                    dc.SaveChanges();
                    #endregion

                    #region//Send Email to User
                    SendVerificationLinkEmail(userCredentials.Email, credentials.ActivationCode.ToString());
                    #endregion
                    status = true;
                }
                #endregion
                return(status);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #5
0
 public bool VerifyAccount(string id)
 {
     try
     {
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             dc.Configuration.ValidateOnSaveEnabled = false;
             var compare = dc.UserCredentials.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
             if (compare != null)
             {
                 compare.IsEmailVerified = true;
                 dc.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #6
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);
            }
        }
Exemple #7
0
        //to delete the specific meeting

        public bool DeleteMeetingDetails(int id)
        {
            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//Deleting the Schedule for specific meeting
                        var scheduleEntity = dc.Schedules.FirstOrDefault(a => a.ScheduleId == meetingEntity.ScheduleId);
                        dc.Schedules.Remove(scheduleEntity);
                        dc.SaveChanges();
                        #endregion

                        #region//Deleting the meeting
                        meetingEntity.DeletedAt = DateTime.Now;
                        dc.SaveChanges();
                        #endregion

                        #region//Deleting the meeting attendees
                        var meetingAttendeeObjects = dc.MeetingsAttendees.Where(a => a.MeetingId == id).ToList();
                        foreach (var item in meetingAttendeeObjects)
                        {
                            dc.MeetingsAttendees.Remove(item);
                            dc.SaveChanges();
                        }
                        #endregion
                        status = true;
                    }
                }

                return(status);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        //to update the data from edit training form
        public bool UpdateTrainingDetails(int id, TrainingVM trainer)
        {
            try
            {
                bool status = false;
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    var trainerEntity = dc.Trainings.FirstOrDefault(a => a.TrainingId == id);
                    if (trainerEntity == null)
                    {
                        return(status);
                    }
                    else
                    {
                        //updating schedule for specific record
                        var scheduleEntity = dc.Schedules.FirstOrDefault(a => a.ScheduleId == trainerEntity.ScheduleId);
                        scheduleEntity.StartTime = trainer.StartTime;
                        scheduleEntity.EndTime   = trainer.EndTime;
                        scheduleEntity.RoomId    = trainer.RoomId;
                        dc.SaveChanges();

                        //updating training for specific record
                        trainerEntity.Topic       = trainer.Topic;
                        trainerEntity.Description = trainer.Description;
                        //for update schedule Id is not require cause it is already present in database.
                        //for update User Id is not require cause it is already present in database.
                        trainerEntity.UpdatedAt = DateTime.Now;
                        dc.SaveChanges();
                        status = true;

                        return(status);
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public ActionResult VerifyPassword(ResetPasswordVM reset)
 {
     try
     {
         var message = " ";
         #region// reseting the password
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             var user = dc.UserCredentials.Where(a => a.ActivationCode.ToString() == reset.ActivationCode.ToString()).FirstOrDefault();
             if (user != null)
             {
                 if (reset.NewPassword == reset.ConfirmPassword)
                 {
                     user.Password = Crypto.Hash(reset.NewPassword);
                     dc.SaveChanges();
                     message = "new password updated successfully go and login";
                 }
                 else
                 {
                     message = "password and confirm password does not match";
                 }
             }
             else
             {
                 message = "something went wrong";
             }
         }
         #endregion
         ViewBag.Message = message;
         return(View(reset));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }