Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="changedEvent"></param>
        /// <param name="actionValues"></param>
        /// <returns></returns>
        public ActionResult CustomSave(CalendarEvent changedEvent, FormCollection actionValues)
        {

            var action = new DataAction(DataActionTypes.Update, changedEvent.id, changedEvent.id);
            string currentUser = HttpContext.User.Identity.Name;
            if (actionValues["actionButton"] != null)
            {
                try
                {
                    string actionButton = actionValues["actionButton"];
                    if (actionButton == "Save")
                    {
                        var eventToUpdate = Repository.GetAll<CalendarEvent>().FirstOrDefault(ev => ev.id == action.SourceId);
                        if (eventToUpdate != null)
                        {
                            if (eventToUpdate.user_name == currentUser)
                            {
                                if (!CheckTimeCurrent(changedEvent.start_date))
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = "Please check start time!";
                                }
                                try
                                {
                                    if (!Repository.UpdateEvents(changedEvent))
                                    {
                                        action.Type = DataActionTypes.Error;
                                        action.Message = "Update faild!";
                                    }
                                    DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                                }
                                catch (Exception ex)
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = ex.Message;
                                }
                            }
                            else
                            {
                                action.Type = DataActionTypes.Error;
                                action.Message = "You can not fix, only the creator can edit!";
                            }

                        }
                        else
                        {
                            action.Type = DataActionTypes.Insert;
                            if (!CheckStartDateAndEndDateInRoom(changedEvent.room_id, changedEvent.start_date, changedEvent.end_date))
                            {
                                action.Type = DataActionTypes.Delete;
                                action.Message = "Please check start time!";
                            }
                            else
                            {
                                if (!CheckTimeCurrent(changedEvent.start_date))
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = "Please check start time!";
                                }
                                try
                                {
                                    if (changedEvent.laptop_id == "NotUse")
                                        changedEvent.laptop_id = null;

                                    if (changedEvent.phone_id == "NotUse")
                                        changedEvent.phone_id = null;
                                     
                                    if (changedEvent.projector_id == "NotUse")
                                        changedEvent.projector_id = null;
                                    
                                    if (User.IsInRole("GA"))
                                        changedEvent.for_dept = "GA";

                                    if (User.IsInRole("Employee"))
                                        changedEvent.for_dept = "Employee";

                                    changedEvent.user_name = HttpContext.User.Identity.Name;
                                    changedEvent.creator_id = Guid.Parse(HttpContext.User.Identity.GetUserId());

                                    if (changedEvent.projector_id != null)
                                    {
                                        if (!CheckProjectorExitsInRoom(changedEvent.room_id))
                                        {
                                            action.Type = DataActionTypes.Error;
                                            action.Message = "Current rooms were installed the projector!";
                                        }
                                        else
                                        {
                                            if (!Repository.Insert(changedEvent))
                                            {
                                                action.Type = DataActionTypes.Error;
                                                action.Message = "Create faild!";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!Repository.Insert(changedEvent))
                                        {
                                            action.Type = DataActionTypes.Error;
                                            action.Message = "Create faild!";
                                        }
                                    }
                                    
                                }
                                catch (Exception ex)
                                { 
                                    action.Type = DataActionTypes.Error;
                                    action.Message = ex.Message;
                                }
                            }
                        }
                    }
                    else if (actionButton == "Delete")
                    {
                        action.Type = DataActionTypes.Delete;
                        changedEvent = Repository.GetAll<CalendarEvent>().SingleOrDefault(ev => ev.id == action.SourceId);
                        if (changedEvent != null)
                        {
                            if (changedEvent.user_name == currentUser)
                            {
                                try
                                {
                                    if (!Repository.Delete(changedEvent))
                                    {
                                        action.Type = DataActionTypes.Error;
                                        action.Message = "Delete faild!";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = "Delete faild! " + ex.Message;
                                }
                            }
                            else
                            {
                                action.Type = DataActionTypes.Error;
                                action.Message = "You can not delete, only the creator can delete! ";
                            }
                        }
                        else
                        {
                            action.Type = DataActionTypes.Error;
                            action.Message = "Event id notfound!";
                        }
                    }
                }

                catch (Exception ex)
                {
                    action.Type = DataActionTypes.Error;
                    action.Message = "Faild! " + ex.Message;
                }
            }
            else
            {
                action.Type = DataActionTypes.Error;
                action.Message = "action notfound!";
            }


            return (new SchedulerFormResponseScript(action, changedEvent));

        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="changedEvent"></param>
        /// <param name="actionValues"></param>
        /// <returns></returns>
        public ContentResult NativeSave(CalendarEvent changedEvent, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);
            string currentUser = HttpContext.User.Identity.Name;
            try
            {
                switch (action.Type)
                {
                    case DataActionTypes.Insert:
                        if (!CheckStartDateAndEndDateInRoom(changedEvent.room_id, changedEvent.start_date, changedEvent.end_date))
                        {
                            action.Type = DataActionTypes.Delete;
                            action.Message = "Time check faild!";
                        }
                        else
                        {
                            if (!CheckTimeCurrent(changedEvent.start_date))
                            {
                                action.Type = DataActionTypes.Delete;
                                action.Message = "Time check faild!";
                            }
                            else
                            {
                                try
                                {
                                    if (changedEvent.laptop_id == "NotUse")
                                        changedEvent.laptop_id = null;

                                    if (changedEvent.phone_id == "NotUse")
                                        changedEvent.phone_id = null;

                                    if (changedEvent.projector_id == "NotUse")
                                        changedEvent.projector_id = null;

                                    if (User.IsInRole("GA"))
                                        changedEvent.for_dept = "GA";

                                    if (User.IsInRole("Employee"))
                                        changedEvent.for_dept = "Employee";


                                    changedEvent.user_name = HttpContext.User.Identity.Name;
                                    changedEvent.creator_id = Guid.Parse(HttpContext.User.Identity.GetUserId());

                                    if (changedEvent.projector_id != null)
                                    {
                                        if (!CheckProjectorExitsInRoom(changedEvent.room_id))
                                        {
                                            action.Type = DataActionTypes.Error;
                                            action.Message = "Current rooms were installed the projector!";
                                        }
                                        else
                                        {
                                            if (!Repository.Insert(changedEvent))
                                            {
                                                action.Type = DataActionTypes.Error;
                                                action.Message = "Create faild!";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!Repository.Insert(changedEvent))
                                        {
                                            action.Type = DataActionTypes.Error;
                                            action.Message = "Create faild!";
                                        }
                                    }

                                }
                                catch (Exception ex)
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = ex.Message;
                                }
                            }

                        }
                        break;
                    case DataActionTypes.Delete:
                        changedEvent = Repository.GetAll<CalendarEvent>().SingleOrDefault(ev => ev.id == action.SourceId);
                        if (changedEvent != null)
                        {
                            if (changedEvent.user_name == currentUser)
                            {
                                try
                                {
                                    if (!Repository.Delete(changedEvent))
                                    {
                                        action.Type = DataActionTypes.Error;
                                        action.Message = "Delete";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = ex.Message;
                                }
                            }
                            else
                            {
                                action.Type=DataActionTypes.Error;
                                action.Message = "You can not delete, only the creator can delete!";
                            }
                            
                        }
                        else
                        {
                            action.Type = DataActionTypes.Error;
                            action.Message = "Event id notfound!";
                        }
                        break;
                    default:// "update"                          
                        var eventToUpdate = Repository.GetAll<CalendarEvent>().SingleOrDefault(ev => ev.id == action.SourceId);
                        if (eventToUpdate != null)
                        {
                            if (eventToUpdate.user_name == currentUser)
                            {
                                if (!CheckTimeCurrent(changedEvent.start_date))
                                {
                                    action.Type = DataActionTypes.Error;
                                    action.Message = "Time check!";
                                }
                                else
                                {
                                    if (changedEvent.projector_id == "null")
                                    {
                                        changedEvent.projector_id = null;
                                    }
                                    if (changedEvent.laptop_id == "null")
                                    {
                                        changedEvent.laptop_id = null;
                                    }
                                    if (changedEvent.phone_id == "null")
                                    {
                                        changedEvent.phone_id = null;
                                    }
                                    changedEvent.creator_id = Guid.Parse(HttpContext.User.Identity.GetUserId());
                                    changedEvent.user_name = HttpContext.User.Identity.Name;
                                    try
                                    {
                                        if (!Repository.UpdateEvents(changedEvent))
                                        {
                                            action.Type = DataActionTypes.Error;
                                            action.Message = "Update";
                                        }
                                        DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                                    }
                                    catch (Exception ex)
                                    {
                                        action.Type = DataActionTypes.Error;
                                        action.Message = ex.Message;
                                    }
                                }
                            }
                            else
                            {
                                action.Type = DataActionTypes.Error;
                                action.Message = "You can not fix, only the creator can edit!";
                            }
                        }
                        break;
                }
                if (changedEvent != null)
                    action.TargetId = changedEvent.id;
            }
            catch(Exception ex)
            {
                action.Type = DataActionTypes.Error;
                action.Message = ex.Message;
            }

            return (new AjaxSaveResponse(action));
        }
Exemplo n.º 3
0
        public ActionResult LightboxCustomControl(CalendarEvent calendarEvent)
        {
            var calendarEvents = Repository.GetAll<CalendarEvent>().ToList();
            var current = calendarEvents.FirstOrDefault(e => e.id == calendarEvent.id);
            var events = calendarEvents.Where(ev => ev.start_date.Day == DateTime.Now.Day).ToList();
            //if()
            var laptops = Repository.GetAll<Laptop>().Where(l => l.is_empty == false).OrderBy(l => l.position).ToList();
            var projectors = Repository.GetAll<Projector>().Where(p => p.is_empty == false).OrderBy(p => p.position).ToList();
            var phones = Repository.GetAll<Phone>().Where(p => p.is_empty == false).OrderBy(p => p.position).ToList();
            List<Room> rooms = null;

            if (User.IsInRole("Manager") || User.IsInRole("General Director") || User.IsInRole("GA"))
            {
                rooms = Repository.GetAll<Room>().OrderBy(r => r.position).ToList();
            }
            //else if (User.IsInRole("GA"))
            //{
            //    rooms = Repository.GetAll<Room>().Where(r => r.for_dept == "GA").OrderBy(r => r.position).ToList();
            //}
            else if (User.IsInRole("Employee"))
            {
                rooms = Repository.GetAll<Room>().Where(r => r.for_dept == "Employee").OrderBy(r => r.position).ToList();
            }

            // List laptop
            List<Laptop> listlaptops = (from lap in laptops
                                        where events.All(ev => lap.laptop_id != ev.laptop_id)
                                        select lap).ToList();

            // List projector
            List<Projector> listprojectors = (from project in projectors
                                              where events.All(ev => project.projector_id != ev.projector_id)
                                              select project).ToList();

            // List Phone

            List<Phone> listphones = (from phone in phones
                                      where events.All(ev => phone.phone_id != ev.phone_id)
                                      select phone).ToList();
            if (current == null)
            {
                ViewBag.laptop_id = new SelectList(listlaptops, "laptop_id", "laptop_name");
                ViewBag.phone_id = new SelectList(listphones, "phone_id", "phone_name");
                ViewBag.projector_id = new SelectList(listprojectors, "projector_id", "projector_name");
                ViewBag.room_id = new SelectList(rooms, "key", "label");

                current = calendarEvent;
            }
            else
            {
                ViewBag.laptop_id = new SelectList(laptops, "laptop_id", "laptop_name", current.laptop_id);
                ViewBag.phone_id = new SelectList(phones, "phone_id", "phone_name", current.phone_id);
                ViewBag.projector_id = new SelectList(projectors, "projector_id", "projector_name", current.projector_id);
                ViewBag.room_id = new SelectList(rooms, "key", "label", current.room_id);
            }
            return View(current);
        }