//to retrieve the data to display list
 public List <TrainingListVM> GetTrainingDetails()
 {
     try
     {
         var trainingList = new List <TrainingListVM>();
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             var data = dc.Trainings.ToList();
             foreach (var item in data)
             {
                 TrainingListVM training = new TrainingListVM();
                 if (item.DeletedAt == null)
                 {
                     training.TrainingId = item.TrainingId;
                     training.EndTime    = item.Schedule.EndTime.Value;
                     training.StartTime  = item.Schedule.StartTime.Value;
                     training.Topic      = item.Topic;
                     var name = string.Concat(item.User.FirstName + item.User.LastName);
                     training.TrainerName = name;
                     training.Description = item.Description;
                     training.RoomName    = item.Schedule.RoomDetail.RoomName;
                     trainingList.Add(training);
                 }
             }
         }
         return(trainingList);
     }
     catch (Exception)
     {
         throw null;
     }
 }
        //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);
            }
        }
Beispiel #3
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);
     }
 }
 //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);
     }
 }
Beispiel #5
0
 public User GetUser(LoginVM login)
 {
     try
     {
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             var isValidUser = dc.UserCredentials.Where(a => a.Email == login.Email).FirstOrDefault();
             if (isValidUser != null)
             {
                 if (string.Compare(Crypto.Hash(login.Password), isValidUser.Password) == 0 && (isValidUser.IsEmailVerified == true))
                 {
                     var userObj = dc.Users.Where(a => a.UserId == isValidUser.UserId).FirstOrDefault();
                     return(userObj);
                 }
                 else
                 {
                     return(null);
                 }
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #6
0
 public bool SendMailForForgotPasswordLink(string emailId)
 {
     try
     {
         IRegistrationInfo details = new RegistrationInfo();
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             var account = dc.UserCredentials.Where(a => a.Email == emailId).FirstOrDefault();
             if (account != null && account.IsEmailVerified == true)
             {
                 //send mail to user
                 bool status = details.SendVerificationLinkEmail(account.Email, account.ActivationCode.ToString(), "VerifyPassword");
                 if (status)
                 {
                     dc.Configuration.ValidateOnSaveEnabled = false;
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #7
0
 public List <UsersVM> GetUsersDetails()
 {
     try
     {
         var userList = new List <UsersVM>();
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             //var data = dc1.Schedules.ToList();
             var data = dc.Users.ToList();
             foreach (var item in data)
             {
                 UsersVM user = new UsersVM();
                 if (item.DeletedAt == null)
                 {
                     var name = string.Concat(item.FirstName + " " + item.LastName);
                     user.UserName = name;
                     user.UserId   = item.UserId;
                     userList.Add(user);
                 }
             }
         }
         return(userList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #8
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);
            }
        }
Beispiel #9
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;
            }
        }
Beispiel #10
0
 public bool IsEmailExist(String emailID)
 {
     try
     {
         using (TrainingAppEntities1 dc = new TrainingAppEntities1())
         {
             var result = dc.UserCredentials.Where(a => a.Email == emailID).FirstOrDefault();
             return(result == null ? false : true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #11
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);
            }
        }
Beispiel #12
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);
            }
        }
Beispiel #13
0
        // to retrive the data to display list

        public List <MeetingListVM> GetMeetingInfo()
        {
            try
            {
                var meetingList = new List <MeetingListVM>();
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    #region // Retriving meeting list
                    var data = dc.Meetings.ToList();
                    foreach (var item in data)
                    {
                        MeetingListVM meeting = new MeetingListVM();
                        if (item.DeletedAt == null)
                        {
                            meeting.MeetingId     = item.MeetingId;
                            meeting.EndTime       = item.Schedule.EndTime.Value;
                            meeting.StartTime     = item.Schedule.StartTime.Value;
                            meeting.MeetingName   = item.MeetingName;
                            meeting.Agenda        = item.Agenda;
                            meeting.OrganiserName = string.Concat(item.User.FirstName + item.User.LastName);
                            List <AttendeeVM> attendeeList = new List <AttendeeVM>();
                            foreach (var attendee in item.MeetingsAttendees)
                            {
                                AttendeeVM attend = new AttendeeVM();
                                attend.AttendeeID   = attendee.User.UserId;
                                attend.AttendeeName = attendee.User.FirstName;
                                attendeeList.Add(attend);
                            }
                            meeting.AttendeeList = attendeeList;
                            meeting.RoomName     = item.Schedule.RoomDetail.RoomName;
                            meetingList.Add(meeting);
                        }
                    }
                    #endregion
                }
                return(meetingList);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public List <RoomVM> GetRoomsByTime(TimeSlotVM times)
        {
            try
            {
                DateTime startTime = times.StartTime;
                DateTime endTime   = times.EndTime;
                var      roomList  = new List <RoomVM>();
                using (TrainingAppEntities1 dc = new TrainingAppEntities1())
                {
                    var bookedSlotList = dc.Schedules.Where(a => a.StartTime == startTime || a.EndTime == endTime || (a.StartTime <endTime && a.StartTime> startTime) || (startTime > a.StartTime && endTime < a.EndTime) || (endTime > a.EndTime && startTime < a.StartTime));

                    HashSet <int?> bookedIdList  = new HashSet <int?>();
                    var            uniqueDetails = dc.RoomDetails.ToList();
                    int            count         = 0;

                    foreach (var item in bookedSlotList)
                    {
                        bookedIdList.Add(item.RoomId);
                        count++;
                    }
                    Console.WriteLine(count);
                    foreach (var item in bookedIdList)
                    {
                        uniqueDetails.RemoveAll(a => a.RoomId == item);
                    }
                    foreach (var item in uniqueDetails)
                    {
                        RoomVM roomVM = new RoomVM();
                        roomVM.RoomId   = item.RoomId;
                        roomVM.RoomName = item.RoomName;
                        roomList.Add(roomVM);
                    }
                }
                return(roomList);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        //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;
     }
 }