Example #1
0
        public ActionResult Create()
        {
            var context = new VITVSecondContext();

            ViewBag.Employees = context.Employees.ToList();
            return(PartialView());
        }
        public ActionResult Edit(int id, string content, List <string> employees)
        {
            var db     = new VITVSecondContext();
            var confer = db.Conferences.Find(id);

            if (confer != null && !String.IsNullOrEmpty(content))
            {
                confer.Content = content;
                db.SaveChanges();

                db.Conferences.Attach(confer);
                db.Entry(confer).Collection(e => e.Employees).Load();

                List <Employee> lstEmp = confer.Employees.ToList();
                foreach (Employee r in lstEmp)
                {
                    confer.Employees.Remove(r);
                }

                if (employees != null)
                {
                    foreach (string emp in employees)
                    {
                        Employee r = db.Employees.Find(emp);
                        if (r != null)
                        {
                            confer.Employees.Add(r);
                        }
                    }
                }
                db.SaveChanges();
                return(Json(new { success = true, id = confer.Id }));
            }
            return(Json(new { success = false, id = confer.Id }));
        }
Example #3
0
        public override System.Threading.Tasks.Task OnConnected()
        {
            var userId  = Context.User.Identity.GetUserId();
            var context = new VITVSecondContext();
            var user    = context.Employees.Find(userId);
            var client  = clients.Find(c => c.UserId == userId);

            if (client == null)
            {
                client = new ChatClient()
                {
                    UserId        = userId,
                    DisplayName   = user.Name,
                    Avatar        = user.ProfilePicture,
                    ConnectionIds = new List <string> {
                        Context.ConnectionId
                    }
                };
                clients.Add(client);
            }
            else
            {
                client.ConnectionIds.Add(Context.ConnectionId);
            }

            Clients.Others.notifyUserOnline(client);
            return(base.OnConnected());
        }
Example #4
0
        public ActionResult DeleteConfirm(int id, bool permanent)
        {
            var context = new VITVSecondContext();
            var request = context.TaskRequests.Find(id);

            if (permanent)
            {
                var notifications = context.Notifications.Where(n => n.RequestId == id).ToList();
                context.Notifications.RemoveRange(notifications);

                foreach (var joblist in request.JobLists)
                {
                    foreach (var job in joblist.Jobs)
                    {
                        var jobNotifications = context.Notifications.Where(n => n.JobId == job.Id).ToList();
                        context.Notifications.RemoveRange(jobNotifications);
                    }
                }

                context.TaskRequests.Remove(request);
            }
            else
            {
                request.IsDeleted = true;
            }
            context.SaveChanges();
            return(Json(new { success = true }));
        }
Example #5
0
        public ActionResult Delete(int?id)
        {
            var context = new VITVSecondContext();
            var job     = context.Jobs.Find(id);

            return(PartialView(job));
        }
Example #6
0
        public ActionResult Month(string id, int?m, int?y)
        {
            var db = new VITVSecondContext();

            if (string.IsNullOrEmpty(id))
            {
                id = User.Identity.GetUserId();
            }
            if (!m.HasValue)
            {
                m = DateTime.Now.Month;
            }
            if (!y.HasValue)
            {
                y = DateTime.Now.Year;
            }
            var model = new CalendarMonthModel()
            {
                Year     = y.Value,
                Month    = m.Value,
                Employee = db.Employees.Find(id)
            };

            return(View(model));
        }
Example #7
0
        public ActionResult MyProjects()
        {
            var context  = new VITVSecondContext();
            var employee = context.Employees.Find(User.Identity.GetUserId());

            return(View(employee.Projects.Where(p => !p.IsDeleted).ToList()));
        }
        public ActionResult Delete(int id)
        {
            var db   = new VITVSecondContext();
            var noti = db.GroupNotifications.Find(id);

            return(PartialView(noti));
        }
Example #9
0
        public ActionResult Details(int id)
        {
            var context = new VITVSecondContext();
            var job     = context.Jobs.Find(id);

            if (job != null)
            {
                var userId = User.Identity.GetUserId();
                ViewBag.Me = context.Employees.Find(userId);
                var project = context.Projects.Find(job.JobList.TaskRequest.ProjectId);
                ViewBag.CanEdit = User.IsInRole("Admin") || project.Employees.Any(e => e.Id == userId);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView(job));
                }
                else
                {
                    return(View(job));
                }
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
        public ActionResult Add(string content, DateTime start, DateTime end, List <string> employees)
        {
            var db = new VITVSecondContext();

            if (!String.IsNullOrEmpty(content))
            {
                var confer = new Conference()
                {
                    Content = content,
                    Start   = start,
                    End     = end,
                };
                db.Conferences.Add(confer);
                db.SaveChanges();

                if (employees != null)
                {
                    foreach (string emp in employees)
                    {
                        Employee r = db.Employees.Find(emp);
                        if (r != null)
                        {
                            confer.Employees.Add(r);
                        }
                    }
                }
                db.SaveChanges();
                return(Json(new { success = true, id = confer.Id }));
            }
            //TODO
            return(Json(new { success = false }));
        }
Example #11
0
        public ActionResult Delete(int?id)
        {
            var context = new VITVSecondContext();
            var project = context.Projects.Find(id);

            return(PartialView(project));
        }
Example #12
0
        public ActionResult All(int?group, int?m, int?y)
        {
            var db = new VITVSecondContext();

            if (!group.HasValue)
            {
                group = 0;
            }
            if (!m.HasValue || !y.HasValue)
            {
                m = DateTime.Now.Month;
                y = DateTime.Now.Year;
            }
            ;
            var empAttendance = db.Employees.Where(e => group == 0 || e.WorkInfo.GroupId == group).Select(e => new EmployeeAttendance
            {
                EmployeeId   = e.Id,
                EmployeeName = e.Name,
                Dayoffs      = e.PersonalDayoffs.Where(d => d.Start.Month == m && d.Start.Year == y).ToList(),
            }).ToList();
            var model = new CalendarAllModel()
            {
                GroupId             = group.Value,
                Month               = m.Value,
                Year                = y.Value,
                EmployeeAttendances = empAttendance
            };

            ViewBag.Groups = db.Groups.Where(g => g.EmployeeWorkInfos.Count != 0).ToList();
            return(View(model));
        }
Example #13
0
        public ActionResult CheckToken(CheckTokenModel model) //deviceId and tokenId
        {
            var        context    = new VITVSecondContext();
            DeviceUser deviceUser = context.DeviceUsers.FirstOrDefault(du => du.DeviceId == model.Id && du.LoginToken == model.Token);

            try
            {
                if (deviceUser != null)
                {
                    if (DateTime.Now < deviceUser.ExpiredTime)
                    {
                        return(Json(new { Success = true }));
                    }
                    else
                    {
                        return(Json(new { Success = false, error = 1 }));
                    }
                }
                else
                {
                    return(Json(new { Success = false, error = 0 }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new { Success = false, error = e.Message }));
            }
        }
Example #14
0
        public ActionResult Delete(int?id)
        {
            var context = new VITVSecondContext();
            var request = context.TaskRequests.Find(id);

            return(PartialView(request));
        }
Example #15
0
        public ActionResult Delete(int?id)
        {
            var context  = new VITVSecondContext();
            var response = context.JobResponses.Find(id);

            return(PartialView(response));
        }
Example #16
0
        public ActionResult Create(JobResponse response, List <HttpPostedFileBase> attachments)
        {
            var context = new VITVSecondContext();

            response.EmployeeId  = User.Identity.GetUserId();
            response.CreatedTime = DateTime.Now;
            if (attachments != null)
            {
                response.Attachments = new List <ResponseAttachment>();
                foreach (var attachment in attachments)
                {
                    if (attachment != null)
                    {
                        attachment.SaveAs(Server.MapPath("~/Upload/Attachment/" + attachment.FileName));
                        var link = ("/Upload/Attachment/" + attachment.FileName);
                        response.Attachments.Add(new ResponseAttachment
                        {
                            AttachmentLink = link
                        });
                    }
                }
            }
            context.JobResponses.Add(response);
            context.SaveChanges();

            Job job = context.Jobs.Find(response.JobId);

            var notification = new Notification()
            {
                FromId             = User.Identity.GetUserId(),
                NotificationTypeId = NotificationTypes.ReceivedAResponse,
                RequestId          = response.Job.JobList.TaskRequestId,
                Url         = "/TaskRequest/Details/" + response.Job.JobList.TaskRequestId,
                CreatedDate = DateTime.Now
            };

            context.Notifications.Add(notification);
            var employees = new HashSet <Employee>(context.JobResponses.Where(r => r.JobId == response.JobId && r.EmployeeId != response.EmployeeId).Select(r => r.Employee).Distinct());

            foreach (var employee in employees)
            {
                var userNotification = new UserNotification()
                {
                    //IsRead = false,
                    //CreatedTime = DateTime.Now,
                    EmployeeId   = employee.Id,
                    Notification = notification
                };
                context.UserNotifications.Add(userNotification);
            }
            context.SaveChanges();

            foreach (var employee in employees)
            {
                Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <NotificationHub>().Clients.User(employee.Id).reloadNotification();
                Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <NotificationHub>().Clients.User(employee.Id).popupNotification(employee.Id, notification.Id, response.Content);
            }

            return(Json(new { success = true, id = response.Id }));
        }
        public ActionResult Edit(PersonalDayoffModel dayoffModel)
        {
            var userId = User.Identity.GetUserId();

            if (dayoffModel.UserId == User.Identity.GetUserId() || User.IsInRole("Admin"))
            {
                var context = new VITVSecondContext();
                if (ModelState.IsValid)
                {
                    PersonalDayoff dayoff = context.PersonalDayoffs.Find(dayoffModel.Id);

                    if (dayoffModel.TimeOption == "all")
                    {
                        dayoff.AllDay     = true;
                        dayoff.Title      = dayoffModel.Title;
                        dayoff.Start      = dayoffModel.Date.AddHours(9);
                        dayoff.End        = dayoffModel.Date.AddHours(18);
                        dayoff.EmployeeId = dayoffModel.UserId;
                    }
                    else if (dayoffModel.TimeOption == "morning")
                    {
                        dayoff.AllDay     = false;
                        dayoff.Title      = dayoffModel.Title;
                        dayoff.Start      = dayoffModel.Date.AddHours(9);
                        dayoff.End        = dayoffModel.Date.AddHours(12);
                        dayoff.EmployeeId = dayoffModel.UserId;
                    }
                    else if (dayoffModel.TimeOption == "afternoon")
                    {
                        dayoff.AllDay     = false;
                        dayoff.Title      = dayoffModel.Title;
                        dayoff.Start      = dayoffModel.Date.AddHours(14);
                        dayoff.End        = dayoffModel.Date.AddHours(18);
                        dayoff.EmployeeId = dayoffModel.UserId;
                    }
                    else if (dayoffModel.TimeOption == "custom" && dayoffModel.StartTime.HasValue && dayoffModel.EndTime.HasValue)//custom
                    {
                        dayoff.AllDay     = false;
                        dayoff.Title      = dayoffModel.Title;
                        dayoff.Start      = dayoffModel.Date.AddHours(dayoffModel.StartTime.Value.Hour).AddMinutes(dayoffModel.StartTime.Value.Minute);
                        dayoff.End        = dayoffModel.Date.AddHours(dayoffModel.EndTime.Value.Hour).AddMinutes(dayoffModel.EndTime.Value.Minute);
                        dayoff.EmployeeId = dayoffModel.UserId;
                    }
                    else
                    {
                        return(Json(new { success = false, error = "Có lỗi..." }));
                    }
                    context.SaveChanges();
                    //Utilities.SendDayoffPush(dayoff);
                    //Utilities.SendDayoffPushAndroid(dayoff);
                    return(Json(new { success = true }));
                }
                return(Json(new { success = false, error = "Chưa nhập đủ dữ liệu" }));
            }
            else
            {
                return(Json(new { success = false, error = "Không có quyền!!!" }));
            }
        }
        public ActionResult Popup(string employeeId, int notifiId)
        {
            var context    = new VITVSecondContext();
            var userNotifi = context.UserNotifications.Find(employeeId, notifiId);

            return(Json(new { userNotifi.EmployeeId, userNotifi.Notification.Content, userNotifi.Employee.ProfilePicture, userNotifi.Notification.Url }, JsonRequestBehavior.AllowGet));
            //return PartialView(userNotifi);
        }
        public JsonResult Edit(GroupNotification notifi)
        {
            var db = new VITVSecondContext();

            db.Entry(notifi).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(Json(new { success = true }));
        }
        public ActionResult Count()
        {
            var context     = new VITVSecondContext();
            var userId      = User.Identity.GetUserId();
            var notifiCount = context.UserNotifications.Count(n => n.EmployeeId == userId);

            return(Content(notifiCount.ToString()));
        }
 public ActionResult Item(int id)
 {
     var context = new VITVSecondContext();
     var item = context.Jobs.Find(id);
     //var userId = User.Identity.GetUserId();
     //ViewBag.Me = context.Employees.Find(userId);
     return PartialView(item);
 }
        public JsonResult Add(GroupNotification notifi)
        {
            var db = new VITVSecondContext();

            db.GroupNotifications.Add(notifi);
            db.SaveChanges();
            return(Json(new { success = true }));
        }
Example #23
0
        public ActionResult Delete(int id)
        {
            var db = new VITVSecondContext();

            db.Dayoffs.Remove(db.Dayoffs.Find(id));
            db.SaveChanges();
            return(Json(new { success = true, id = id }));
        }
Example #24
0
        public ActionResult Edit(int id)
        {
            var context = new VITVSecondContext();
            var request = context.TaskRequests.Find(id);

            ViewBag.Employees = context.Employees.ToList();
            return(PartialView(request));
        }
Example #25
0
        public ActionResult ChangeStatus(int id, int status)
        {
            var context = new VITVSecondContext();
            var request = context.TaskRequests.Find(id);

            request.Status = status;
            context.SaveChanges();
            return(Json(new { success = true, id = id }));
        }
        public ActionResult EditProperty(int pk, string name, string value)
        {
            var context = new VITVSecondContext();
            var checklist = context.JobLists.Find(pk);
            checklist.GetType().GetProperty(name).SetValue(checklist, value);
            context.SaveChanges();

            return Json(new {success= true});
        }
        public ActionResult Get()
        {
            var      context           = new VITVSecondContext();
            var      userId            = User.Identity.GetUserId();
            DateTime last7Days         = DateTime.Now.AddDays(-7);
            var      userNotifications = context.UserNotifications.Where(n => n.EmployeeId == userId && n.Notification.CreatedDate >= last7Days).OrderByDescending(n => n.Notification.CreatedDate).ToList();

            return(PartialView(userNotifications));
        }
        public JsonResult DeleteConfirm(int id)
        {
            var db   = new VITVSecondContext();
            var noti = db.GroupNotifications.Find(id);

            db.GroupNotifications.Remove(noti);
            db.SaveChanges();
            return(Json(new { success = true }));
        }
Example #29
0
        public PartialViewResult Get10Last(string userId)
        {
            var context  = new VITVSecondContext();
            var myId     = User.Identity.GetUserId();
            var messages = context.Messages.Where(m => (m.SenderId == myId && m.ReceiverId == userId) || (m.SenderId == userId && m.ReceiverId == myId)).OrderByDescending(m => m.CreatedTime).Take(10).ToList();

            messages.Reverse();
            ViewBag.MyId = myId;
            return(PartialView("_Last10", messages));
        }
Example #30
0
        public ActionResult TopNotification()
        {
            var userId  = User.Identity.GetUserId();
            var context = new VITVSecondContext();

            ViewBag.Employee = context.Employees.Find(userId);
            var jobs = context.Jobs.Where(r => r.Employees.Any(e => e.Id == userId)).ToList();

            return(PartialView(jobs));
        }