public ActionResult DeleteVacation(Vacation vacation, int? page,String calendar)
        {
            Vacation vac = (Vacation)db.FindById(vacation.VacationPeriodId);
            double numDays = (vac.DateTo - vac.DateFrom).TotalDays;
            radniDaniZaBrisanje = GetWorkDays(vac.DateFrom, vac.DateTo);
            UsersService users = new UsersService();
            User u = (User)users.FindUserByUsername(HttpContext.User.Identity.Name);
            if (!vac.IsSickLeave)
            {
                int days = u.VacationDays + radniDaniZaBrisanje;
                u.VacationDays = days;
            }

            users.Edit(u);
            db.DeleteVacation(vac.VacationPeriodId);

            if (calendar != null && calendar.Equals("true"))
            {
                return RedirectToAction("initHolidays", "LoadHolidays");
            }
            else
            {
                return SeeVacationsDelete(page);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send notification to all online users when admin change/edit/delete holiday.
        /// </summary>
        /// <param name="type">add, edit, delete</param>
        /// <param name="message">Holiday description.</param>
        /// <param name="sender">Who change/edit/delete holiday.</param>
        public void SendNotification(string type, string message, string sender)
        {
            NotificationService notificationService = new NotificationService();
            UsersService userService = new UsersService();

            User createdBy = (User)userService.FindUserByUsername(sender);
            int userCount = 0;
            foreach (User user in userService.FindAll())
            {
                if (!user.IsUserAdmin && user.IsUserRegistered)
                {
                    Notification notification = new Notification();
                    notification.CreatedBy = createdBy.UserId;
                    notification.DateCreated = DateTime.Now;
                    notification.IsRead = false;
                    notification.SentTo = user.UserId;
                    notification.Description = ChoseDescription(type, message, sender);
                    notificationService.Create(notification);
                    userCount++;
                }
            }
            int maxNotificationId = notificationService.FindLastNotificationId();
            int minNotificationId = maxNotificationId - userCount;

            Clients.All.broadcastNotification(type, message, minNotificationId, maxNotificationId);
        }
        public ActionResult ChangePassPage(ChangePasswordViewModel model)
        {
            UsersService users = new UsersService();
            String currentUsername = User.Identity.Name;
            User user = (User)users.FindUserByUsername(currentUsername);

            if (user.Password.Equals(model.currentPassword))
            {
                if (model.newPassword.Equals(model.confirmNewPass))
                {
                    user.Password = model.confirmNewPass;
                    users.Edit(user);
                }
                else
                {
                    ViewBag.Error = "Password didn't match!!!";
                    return View(model);
                }
            }
            else
            {
                ViewBag.Error = "Password incorect!!";
                return View(model);
            }

            return RedirectToAction("Index", "Home");
        }
        ///<summary>
        ///Show account details.
        ///</summary>
        public ActionResult AccountDetails(String id)
        {
            UsersService users = new UsersService();
            User user = (User)users.FindUserByUsername(id);
            String currentUsername = User.Identity.Name;

            if (user != null)
            {
                if (!currentUsername.Equals(user.Username))
                {
                    return RedirectToAction("Index", "Home");
                }
                UserViewModel model = new UserViewModel();
                model.Email = user.Email;
                model.FirstName = user.FirstName;
                model.LastName = user.LastName;
                model.DateCreated = (DateTime)user.DateCreated;
                model.IsUserRegistered = user.IsUserRegistered;
                model.ProfilePicture = user.ProfilePicture;
                model.Username = user.Username;
                model.VacationDays = user.VacationDays;
                return View(model);
            }
            else
            {
                return View();
            }
        }
Ejemplo n.º 5
0
        public void Send(string name, string message, string recipientName)
        {
            ChatRoomMessageService messageService = new ChatRoomMessageService();
            UsersService userService = new UsersService();
            ChatRoomsService roomService = new ChatRoomsService();

            if (recipientName != null)
            {
                ChatRoomMessage chatRoomMessage = new ChatRoomMessage();
                User sender = userService.FindUserByUsername(name);
                User recipient = userService.FindUserByUsername(recipientName);
                if (sender != null && recipient != null)
                {
                    chatRoomMessage.CreatedBy = sender.UserId;
                    chatRoomMessage.DateCreated = DateTime.Now;
                    chatRoomMessage.Message = message;
                    chatRoomMessage.SentTo = recipient.UserId;
                    int roomId = roomService.FindRoomIdForPrivateChat(chatRoomMessage);
                    if (roomId != -1)
                    {
                        chatRoomMessage.RoomId = roomId;
                    }
                    else
                    {
                        ChatRoom chatRoom = new ChatRoom();
                        chatRoom.CreatedBy = sender.UserId;
                        chatRoom.DateCreated = DateTime.Now;
                        chatRoom.IsDeleted = false;
                        chatRoom.RoomDescription = "Private chat";
                        chatRoom.RoomName = "Private_Chat";
                        chatRoom.IsPrivate = true;
                        int currentRoomId = roomService.CreateWithId(chatRoom);
                        chatRoomMessage.RoomId = currentRoomId;
                    }
                    messageService.Create(chatRoomMessage);
                    previousMessages = messageService.FindAllMessagesForCurrentRoom(chatRoomMessage.RoomId);
                    Clients.User(recipientName).addNewMessageToPage(name, message, recipientName, previousMessages);
                }
            }
            else
            {
                ChatRoomMessage chatRoomMessage = new ChatRoomMessage();
                User sender = userService.FindUserByUsername(name);
                if (sender != null)
                {
                    chatRoomMessage.CreatedBy = sender.UserId;
                    chatRoomMessage.DateCreated = DateTime.Now;
                    chatRoomMessage.Message = message;
                    chatRoomMessage.SentTo = null;
                    chatRoomMessage.RoomId = 1; // MASTER ROOM

                    messageService.Create(chatRoomMessage);
                    previousMessages = messageService.FindAllMessagesForCurrentRoom(chatRoomMessage.RoomId);
                    Clients.All.addNewMessageToPage(name, message, recipientName, previousMessages);
                }
            }
        }
 /// <summary>
 /// Go to change password page for current loged in user.
 /// </summary>
 public ActionResult ChangePassPage(String id)
 {
     UsersService users = new UsersService();
     User user = (User)users.FindUserByUsername(id);
     String currentUsername = User.Identity.Name;
     if (!currentUsername.Equals(user.Username))
     {
         return RedirectToAction("Index", "Home");
     }
     ChangePasswordViewModel model = new ChangePasswordViewModel();
     return View(model);
 }
        ///<summary>
        ///For Admin, to confirm user registration. Also, sending mail to user.
        ///</summary>
        public ActionResult ConfirmRegistration(String id, int? page)
        {
            UsersService users = new UsersService();
            User user = (User)users.FindUserByUsername(id);

            if (user != null)
            {
                if (user.IsUserRegistered)
                {
                    user.IsUserRegistered = false;
                    Contact(user, false);
                }
                else
                {
                    user.IsUserRegistered = true;
                    Contact(user, true);
                }
                users.Edit(user);
            }

            return ShowAllUsers(page);
        }
        public ActionResult EditVacation(int vacationId)
        {
            UsersService users = new UsersService();
            User u = users.FindUserByUsername(HttpContext.User.Identity.Name);
            ViewBag.BrDana = u.VacationDays;
            ViewBag.Flag = flag;

            TestService ser = new TestService();
            if (ser.FindVacationByUserId(u.UserId, vacationId) == true)
            {
                Vacation vac = (Vacation)db.FindById(vacationId);
                if (vac == null)
                {
                    //...
                    return RedirectToAction("SeeVacations");
                }
                Double numDays = (vac.DateTo - vac.DateFrom).TotalDays;
                daniZaVracanje = Convert.ToInt32(numDays);
                String datum = DateTime.Now.ToString("yyyy-MM-dd");
                ViewBag.Datum = datum;
                ViewBag.Bolestan = vac.IsSickLeave;
                datumProveraZaEdit = vac.DateTo;
                datumProveraZaEditPocetak = vac.DateFrom;
                ViewBag.editDateFrom = vac.DateFrom.ToString("yyyy-MM-dd");
                ViewBag.editDateTo = vac.DateTo.ToString("yyyy-MM-dd");
                flag = 0;
                ViewBag.ProveraDaniZaEdit = daniZaProveruZaEdit;
                ViewBag.FlagZaPozivEdita = flagZaPozivEdita;
                flagZaPozivEdita = 0;
                return View(vac);
            }
            else
            {

                return RedirectToAction("SeeVacations");
            }
        }
Ejemplo n.º 9
0
        public void SendMessageNotification(string name, string message, string recipientName)
        {
            NotificationService notificationService = new NotificationService();
            UsersService userService = new UsersService();

            User createdBy = (User)userService.FindUserByUsername(name);
            User sentTo = (User)userService.FindUserByUsername(recipientName);

            Notification notification = new Notification();
            notification.DateCreated = DateTime.Now;
            notification.CreatedBy = createdBy.UserId;
            notification.Description = "New message from " + name;
            notification.IsRead = false;
            notification.SentTo = sentTo.UserId;
            notificationService.Create(notification);
            int notificationId = notification.NotificationId;

            Clients.User(recipientName).broadcastNotification(name, message, recipientName, notificationId);
        }
        public ActionResult RegistracijaOdmora(Vacation vacation)
        {
            int vikend = 0;
            flag = 0;
            UsersService users = new UsersService();
            User u = (User)users.FindById(vacation.UserId);
            String datum = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.Datum = datum;
            Double numDays = (vacation.DateTo - vacation.DateFrom).TotalDays;
            List<Vacation> vacations = db.GetVacationsForCurrentUser(u.UserId);
            numDays -= DaysIsntCountHoliday(vacation);

                brojacRadnihDanaBezVikenda = GetWorkDays(vacation.DateFrom, vacation.DateTo);
                vikend = Convert.ToInt32(numDays) - brojacRadnihDanaBezVikenda;
                numDays -= vikend;

            if (vacation.IsSickLeave && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
            {
                int brojac = 0;
                if (ModelState.IsValid)
                {

                    foreach (Vacation v in vacations)
                    {
                        if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                        {
                            flag = 1;

                        }
                        else
                        {
                            brojac++;
                        }
                    }
                    if (brojac == vacations.Count)
                    {
                        flag = 0;
                        vacation.DateFrom = vacation.DateFrom;
                        vacation.DateTo = vacation.DateTo;
                        db.AddVacation(vacation);
                        return RedirectToAction("initHolidays", "LoadHolidays");
                    }
                    else
                    {
                        flag = 1;
                        return RedirectToAction("RegistracijaOdmora", new { parameterdatum1 = vacation.DateFrom.ToString("yyyy-MM-dd"), parameterdatum2 = vacation.DateTo.ToString("yyyy-MM-dd") });
                    }

                }
                return View();
            }
            else
            {
                if (Convert.ToInt32(numDays) <= u.VacationDays && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
                {
                    int brojac = 0;
                    if (ModelState.IsValid)
                    {
                        foreach (Vacation v in vacations)
                        {
                            if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                            {
                                flag = 1;

                            }
                            else
                            {

                                brojac++;
                            }
                        }

                        if (brojac == vacations.Count)
                        {
                            flag = 0;
                            vacation.DateFrom = vacation.DateFrom;
                            vacation.DateTo = vacation.DateTo;
                            db.AddVacation(vacation);
                            int days = u.VacationDays - Convert.ToInt32(numDays);
                            u.VacationDays = days;
                            users.Edit(u);
                            return RedirectToAction("initHolidays", "LoadHolidays");
                        }
                        else
                        {
                            flag = 1;
                            return RedirectToAction("RegistracijaOdmora", new { parameterdatum1 = vacation.DateFrom.ToString("yyyy-MM-dd"), parameterdatum2 = vacation.DateTo.ToString("yyyy-MM-dd") });
                        }

                    }
                    return View();
                }
                else
                {

                    return RedirectToAction("RegistracijaOdmora", new { parameterdatum1 = vacation.DateFrom.ToString("yyyy-MM-dd"), parameterdatum2 = vacation.DateTo.ToString("yyyy-MM-dd") });
                }
                //provera
            }
        }
        public ActionResult RegisterPage(RegisterViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                UsersService userService = new UsersService();
                User currentUser = userService.FindUserByUsername(model.Username);

                if (currentUser != null)
                {
                    ViewBag.Error = "Username already exist!";
                    return View();
                }
                if (!model.Password.Equals(model.repeatPassword))
                {
                    ViewBag.Error = "Password doesn't match!";
                    return View();
                }
                currentUser = userService.FindUserByEmail(model.Email);
                if (currentUser != null)
                {
                    ViewBag.Error = "Email address already exist!!";
                    return View();
                }

                User user = new User();
                user.Email = model.Email;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Password = model.Password;
                user.Username = model.Username;
                user.DateCreated = DateTime.Now;
                user.IsUserAdmin = false;
                user.IsUserRegistered = false;
                user.LastLoginDate = DateTime.Now;
                user.VacationDays = 20;

                if (file != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] array = ms.GetBuffer();
                        if (array.Length > 55000)
                        {
                            ViewBag.Error = "Image size can't be more than ~50Kb!!";
                            return View();
                        }
                        user.ProfilePicture = array;
                    }

                }
                userService.Create(user);
                return RedirectToAction("RegisterOK", "Home");
            }
            return View();
        }
        public ActionResult EditPage(EditAccountViewModel model, HttpPostedFileBase file)
        {
            UsersService users = new UsersService();
            String currentUsername = User.Identity.Name;
            User user = (User)users.FindUserByUsername(currentUsername);

            if (user != null)
            {
                if (!currentUsername.Equals(user.Username))
                {
                    return RedirectToAction("Index", "Home");
                }
            }

            User checkForMail = (User)users.FindUserByEmail(model.Email);
            if (checkForMail == null || checkForMail.Email.Equals(user.Email))
            {
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Email = model.Email;
                if (!model.removeImage)
                {
                    if (file != null)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.InputStream.CopyTo(ms);
                            byte[] array = ms.GetBuffer();
                            if (array.Length > 55000)
                            {
                                ViewBag.Error = "Image size can't be more than ~50Kb!!";
                                return View(model);
                            }
                            user.ProfilePicture = array;
                        }
                    }
                }
                else
                {
                    user.ProfilePicture = null;
                }

                users.Edit(user);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ViewBag.Error = "Email address already exist!!";
                return View(model);
            }
        }
        /// <summary>
        /// Go to edit page for current Loged in user.
        /// </summary>
        public ActionResult EditPage(String id)
        {
            UsersService users = new UsersService();
            User user = (User)users.FindUserByUsername(id);
            String currentUsername = User.Identity.Name;
            if (user != null)
            {
                if (!currentUsername.Equals(user.Username))
                {
                    return RedirectToAction("Index", "Home");
                }

                EditAccountViewModel model = new EditAccountViewModel();
                model.Email = user.Email;
                model.FirstName = user.FirstName;
                model.LastName = user.LastName;
                model.removeImage = false;
                return View(model);
            }
            else
            {
                return View();
            }
        }
 /// <summary>
 /// Find notification in range for current user.
 /// </summary>
 /// <param name="currentUsername">Username of logged user.</param>
 /// <param name="minNotificationId">Max - notifcationMessage sent count.</param>
 /// <param name="maxNotificationId">Max notification id : last</param>
 /// <returns>My notification.</returns>
 public Notification FindCurrentUserNotificationInRange(string currentUsername, int minNotificationId, int maxNotificationId)
 {
     Notification notification = null;
     UsersService userService = new UsersService();
     while (minNotificationId <= maxNotificationId)
     {
         notification = context.Notifications.Find(minNotificationId);
         User user = userService.FindUserByUsername(currentUsername);
         if (user != null)
         {
             if (user.UserId == notification.SentTo)
             {
                 return notification;
             }
         }
         minNotificationId++;
     }
     return notification;
 }
 public ActionResult SeeVacationsDelete(int? page)
 {
     UsersService users = new UsersService();
     int userId = users.FindUserByUsername(HttpContext.User.Identity.Name).UserId;
     List<Vacation> currentUserVacations = db.GetVacationsForCurrentUser(userId);
     double tempPaginationValue = currentUserVacations.Count() / 6;
     if (currentUserVacations.Count() % 6 != 0) tempPaginationValue++;
     if (tempPaginationValue < page) page--;
     //if (page != 1 && page != tempPaginationValue && 6 * tempPaginationValue == currentUserVacations.Count()) page--;
     String datum = DateTime.Now.ToString("yyyy-MM-dd");
     ViewBag.Datum = datum;
     return View("SeeVacations", currentUserVacations.ToList().ToPagedList(page ?? 1, 6));
 }
        public ActionResult RegistracijaOdmora(String parameterdatum1, String parameterdatum2)
        {
            UsersService users = new UsersService();
            User u = users.FindUserByUsername(HttpContext.User.Identity.Name);
            String datum = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.Datum = datum;
            s1 = parameterdatum1;
            s2 = parameterdatum2;
            ViewBag.Parameterdatum1 = parameterdatum1;
            ViewBag.Parameterdatum2 = parameterdatum2;
            ViewBag.UserId = u.UserId;
            ViewBag.BrDana = u.VacationDays;
            var vac = new Vacation();
            vac.UserId = Int32.Parse(u.UserId.ToString());
            vac.DateFrom = Convert.ToDateTime(parameterdatum1);
            vac.DateTo = Convert.ToDateTime(parameterdatum2);
            daniZaProveru = GetWorkDays(vac.DateFrom, vac.DateTo);
            ViewBag.DaniZaProveru = daniZaProveru;
            ViewBag.Flag = flag;
            flag = 0;

            return View(vac);
        }
        public ActionResult Logout()
        {
            UsersService userService = new UsersService();
            User currentUser = userService.FindUserByUsername(currentUserOffline);
            if (ChatController.usersOnline != null)
            {
                foreach (UsersLite us in ChatController.usersOnline)
                {
                    if (us.username == currentUserOffline)
                    {
                        us.activity = true;
                        ChatController.usersOnline.First(d => d.username == currentUserOffline).activity = false;
                        DateTime dateNow=DateTime.Now;
                        ChatController.usersOnline.First(d => d.username == currentUserOffline).lastSeenOn = dateNow.ToString("yyyy-MM-dd");
                        currentUser.LastLoginDate = dateNow;
                        userService.Edit(currentUser);
                    }

                    ViewBag.users = ChatController.usersOnline;
                }
            }
            FormsAuthentication.SignOut();
            HttpCookie ck = Request.Cookies[FormsAuthentication.FormsCookieName];
            ck.Expires = DateTime.Now;
            return RedirectToRoute("home");
        }
        ///<summary>
        ///Show only approved registered users.
        ///</summary>
        public ActionResult showRegOnly()
        {
            UsersService users = new UsersService();
            List<User> model = users.FindAll().ToList();
            List<User> withoutAdmin = new List<User>();

            foreach (User user in model)
            {
                if (!user.IsUserAdmin && user.IsUserRegistered)
                {
                    withoutAdmin.Add(user);
                }
            }

            return View(withoutAdmin);
        }
        ///<summary>
        ///Show all registered users.
        ///</summary>
        public ActionResult ShowAllUsers(int? page)
        {
            UsersService users = new UsersService();
            List<User> model = users.FindAll().ToList();
            List<User> withoutAdmin = new List<User>();

            foreach (User user in model)
            {
                if (!user.IsUserAdmin)
                {
                    withoutAdmin.Add(user);
                }
            }
            int? currentPage = ReturnPaginationPage(withoutAdmin, page);
            return View("ShowAllUsers", withoutAdmin.ToList().ToPagedList(currentPage ?? 1, 6));
        }
        /// <summary>
        /// Reset all vacation days for registered users to 20.
        /// </summary>
        public ActionResult ResetVacationDays()
        {
            UsersService userService = new UsersService();
            List<User> users = userService.FindAll();

            foreach (User user in users)
            {
                user.VacationDays = 20;
                userService.Edit(user);
            }

            return RedirectToAction("ShowAllUsers");
        }
        private void revertOldVacationDays(Holiday h)
        {
            TestService vacationService = new TestService();
            UsersService users = new UsersService();
            List<Vacation> vacations = vacationService.GetVacations().ToList();
            double addMoreDaysToVacation = 0;
            foreach (Vacation v in vacations)
            {
                if (v.IsSickLeave) continue;

                //ako se praznik nalazi ceo izmedju, povecaj dane za sve.
                if (h.DateFrom >= v.DateFrom && h.DateFrom <= v.DateTo)
                {
                    if (h.DateTo <= v.DateTo)
                    {
                        addMoreDaysToVacation = (h.DateTo - h.DateFrom).TotalDays;
                    }
                    else
                    {
                        addMoreDaysToVacation = (v.DateTo - h.DateFrom).TotalDays;
                    }
                }
                else if (h.DateFrom <= v.DateFrom && h.DateTo >= v.DateTo)
                {
                    addMoreDaysToVacation = (v.DateTo - v.DateFrom).TotalDays;
                }
                else if (h.DateFrom <= v.DateFrom && h.DateTo <= v.DateTo && h.DateTo >= v.DateFrom)
                {

                    addMoreDaysToVacation = (h.DateTo - v.DateFrom).TotalDays;
                }

                if (addMoreDaysToVacation > 0)
                {
                    User u = (User)users.FindById(v.UserId);
                    u.VacationDays -= Convert.ToInt32(addMoreDaysToVacation);
                    users.Edit(u);
                }
            }
        }
        public IList<ChatMessageModel> LoadPrivateMessagesHistory(string userFrom, string userTo)
        {
            UsersService userService = new UsersService();
            ChatRoomMessageService msgService = new ChatRoomMessageService();
            User sender = userService.FindUserByUsername(userFrom);
            User recipient = userService.FindUserByUsername(userTo);

            ChatRoomMessage messageTemp = new ChatRoomMessage();
            messageTemp.CreatedBy = sender.UserId;
            messageTemp.SentTo = recipient.UserId;

            int roomId = FindRoomIdForPrivateChat(messageTemp);

            if (roomId != -1)
            {
                return msgService.FindAllMessagesForCurrentRoom(roomId).ToList();
            }

            return null;
        }
        public ActionResult LoginPage(LoginViewModel user)
        {
            if (user.Password == null || user.UserName == null)
            {
                return View();
            }

            UsersService userService = new UsersService();
            User currentUser = userService.FindUserByUsername(user.UserName);
            currentUserOffline = currentUser.Username;

            if (currentUser == null)
            {
                ViewBag.Error = "Wrong username..!";
                return View();
            }
            else
            {
                if (!currentUser.Password.Equals(user.Password))
                {
                    ViewBag.Error = "Wrong password combination!";
                    return View();
                }

                if (!currentUser.IsUserRegistered)
                {
                    if (!currentUser.IsUserAdmin)
                    {
                        ViewBag.Error = "Your account isn't approved yet.Check your email.";
                        return View();
                    }
                }

                byte[] tempPicture = currentUser.ProfilePicture;
                currentUser.ProfilePicture = null; // set picture to null, for JsonConverter.
                ICollection<Vacation> tempVacation = currentUser.Vacations;
                ICollection<Holiday> tempHolidays = currentUser.Holidays;
                ICollection<ChatRoom> tempChatRoom = currentUser.ChatRooms;
                ICollection<ChatRoomMessage> tempChatRoomMessage = currentUser.ChatRoomMessages;
                ICollection<Notification> tempNotification = currentUser.Notifications;

                currentUser.Vacations = null;
                currentUser.Holidays = null;
                currentUser.ChatRooms = null;
                currentUser.ChatRoomMessages = null;
                currentUser.Notifications = null;
                FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(15), false,
                    JsonConvert.SerializeObject(currentUser, Formatting.None,
                        new JsonSerializerSettings()
                        {
                            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        })
                    );
                HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat));
                ck.Expires = DateTime.Now.AddMinutes(15);

                Response.Cookies.Add(ck);
               // currentUser.LastLoginDate = DateTime.Now;
                currentUser.ProfilePicture = tempPicture;
                currentUser.Holidays = tempHolidays;
                currentUser.Vacations = tempVacation;
                currentUser.ChatRooms = tempChatRoom;
                currentUser.ChatRoomMessages = tempChatRoomMessage;
                currentUser.Notifications = tempNotification;
                userService.Edit(currentUser);
                ViewBag.Error = "";
                return RedirectToRoute("home");
            }
        }
        public ActionResult EditVacation(Vacation vacation, int? page,String calendar)
        {
            int vikend1 = 0;
            int vikend2 = 0;
            int vikend3 = 0;
            int vikend4 = 0;
            int razlikaZaVikendDane = 0;
            int razlikaZaVikendDanePocetak = 0;
            brojacRadnihDanaZaEditBezVikenda = 0;
            brojacRadnihDanaZaEditBezVikendaFrom = 0;
            String datum = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.Datum = datum;
            UsersService users = new UsersService();
            User u = (User)users.FindById(vacation.UserId);
            Double numDays = (vacation.DateTo - vacation.DateFrom).TotalDays;
            Double povecavanjeOdmora = (vacation.DateTo - datumProveraZaEdit).TotalDays;
            Double povecavanjeOdmoraZaPocetak = (vacation.DateFrom - datumProveraZaEditPocetak).TotalDays;
            Vacation oldVacation = (Vacation)db.FindById(vacation.VacationPeriodId);
            List<Vacation> vacations = db.GetVacationsForCurrentUser(u.UserId);
            double oldHolidayVacationCount = DaysIsntCountHoliday(oldVacation);
            double totalHolidayDays = oldHolidayVacationCount - DaysIsntCountHoliday(vacation);
            numDays += totalHolidayDays;
            if (vacation.DateTo > datumProveraZaEdit)
            {
                brojacRadnihDanaZaEditBezVikenda = GetWorkDays(datumProveraZaEdit, vacation.DateTo);
                vikend1 = Convert.ToInt32(povecavanjeOdmora) - brojacRadnihDanaZaEditBezVikenda;
                razlikaZaVikendDane += vikend1;

            }
            else if (vacation.DateTo <= datumProveraZaEdit)
            {
                brojacRadnihDanaZaEditBezVikenda = -(GetWorkDays(vacation.DateTo, datumProveraZaEdit));
                vikend2 = -(Convert.ToInt32(povecavanjeOdmora)) + brojacRadnihDanaZaEditBezVikenda;
                razlikaZaVikendDane -= vikend2;

            }

            if (vacation.DateFrom > datumProveraZaEditPocetak)
            {
                brojacRadnihDanaZaEditBezVikendaFrom = GetWorkDays(datumProveraZaEditPocetak, vacation.DateFrom);
                vikend3 = (Convert.ToInt32(povecavanjeOdmoraZaPocetak)) - brojacRadnihDanaZaEditBezVikendaFrom;
                razlikaZaVikendDanePocetak -= vikend3;

            }
            else
            {
                brojacRadnihDanaZaEditBezVikendaFrom = -(GetWorkDays(vacation.DateFrom, datumProveraZaEditPocetak));
                vikend4 = -(Convert.ToInt32(povecavanjeOdmoraZaPocetak)) + brojacRadnihDanaZaEditBezVikendaFrom;
                razlikaZaVikendDanePocetak += vikend4;

            }

            if (vacation.IsSickLeave && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
            {
                int brojac = 0;
                foreach (Vacation v in vacations)
                {
                    if (vacation.VacationPeriodId == v.VacationPeriodId)
                    {
                        brojac++;
                        continue;
                    }
                    if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                    {

                        flag = 1;

                    }
                    else
                    {
                        brojac++;
                    }
                }
                if (brojac == vacations.Count)
                {
                    flag = 0;
                    db.EditVacation(vacation);
                    if (calendar != null && calendar.Equals("true")) {
                        return RedirectToAction("initHolidays", "LoadHolidays");
                    }
                    else
                    {
                        return SeeVacations(page);
                    }
                }
                else
                {
                    flag = 1;
                    if (calendar != null && calendar.Equals("true"))
                    {
                        return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId, calendar = "true" });
                    }
                    else
                    {
                        return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId });

                    }
                }

            }
            else
            {
               if (Convert.ToInt32(brojacRadnihDanaZaEditBezVikenda - brojacRadnihDanaZaEditBezVikendaFrom)> u.VacationDays)
                {
                    daniZaProveruZaEdit = brojacRadnihDanaZaEditBezVikenda - brojacRadnihDanaZaEditBezVikendaFrom;
                    flagZaPozivEdita = 1;
                }
                if (Convert.ToInt32(brojacRadnihDanaZaEditBezVikenda - brojacRadnihDanaZaEditBezVikendaFrom) <= u.VacationDays && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(datum))) && (DateTime.Parse(vacation.DateTo.ToString("yyyy-MM-dd")) > (DateTime.Parse(vacation.DateFrom.ToString("yyyy-MM-dd")))))
                {
                    int brojac = 0;

                    if (ModelState.IsValid)
                    {
                        foreach (Vacation v in vacations)
                        {
                            if (vacation.VacationPeriodId == v.VacationPeriodId)
                            {
                                brojac++;
                                continue;
                            }
                            if ((vacation.DateFrom >= v.DateFrom && vacation.DateFrom < v.DateTo) || (vacation.DateTo >= v.DateFrom && vacation.DateTo <= v.DateTo) || (vacation.DateFrom <= v.DateFrom && vacation.DateTo >= v.DateTo))
                            {
                                flag = 1;
                            }
                            else
                            {
                                brojac++;
                            }
                        }
                        if (brojac == vacations.Count)
                        {
                            flag = 0;
                            int days = u.VacationDays - Convert.ToInt32(numDays) + daniZaVracanje + razlikaZaVikendDane + razlikaZaVikendDanePocetak;
                            u.VacationDays = days;
                            users.Edit(u);
                            db.EditVacation(vacation);
                            daniZaVracanje = Convert.ToInt32(numDays);
                            if (calendar != null && calendar.Equals("true"))
                            {
                                return RedirectToAction("initHolidays", "LoadHolidays");
                            }
                            else
                            {
                                return SeeVacations(page);
                            }
                        }
                        else
                        {
                            flag = 1;
                            if (calendar != null && calendar.Equals("true"))
                            {
                                return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId, calendar = "true" });
                            }
                            else
                            {
                                return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId });

                            }
                        }

                    }
                    return View();
                }
                else
                {
                    if (calendar != null && calendar.Equals("true"))
                    {
                        return RedirectToAction("initHolidays", "LoadHolidays");
                    }
                    else
                    {
                        flagZaPozivEdita = 1;
                        return RedirectToAction("EditVacation", new { vacationId = vacation.VacationPeriodId, calendar = "true" });
                    }
                }
            }
        }