Exemplo n.º 1
0
        /// <summary>
        /// Invio mail con password - ToDo
        /// </summary>
        /// <param name="NotificationType">Tipo notifica</param>
        /// <returns></returns>
        public bool NotificationSendRecover(
            Domain.TicketUser User,
            Domain.DTO.DTO_NotificationSettings Settings,
            String NewPassword)
        {
            //Testo esempio:

            /* Le sue credenziali per l'accesso al servizio ticket sono le seguenti:
             * Mail: [PlaceHoldersType.UserMail]
             * Password: [PlaceHoldersType.UserPassword]
             * Indirizzo per l'accesso: [PlaceHoldersType.UserTokenUrl]
             */

            //Creo oggetto SETTINGS (me lo farò passare...)
            //Settings.LangCode = User.LanguageCode;

            // = new Domain.DTO.DTO_NotificationSettings
            //{
            //    BaseUrl = "http://blablalba",
            //    DateTimeFormat = "0:dd/MM/yy H:mm:ss",
            //    LangCode = User.LanguageCode,
            //    CategoriesTemplate = "",
            //    IntCategoryType = null,
            //    IntTicketStatus = null
            //};

            //Creo oggetto DATA
            Domain.DTO.DTO_NotificationData Data = new Domain.DTO.DTO_NotificationData();
            bool   IsPerson = (User.Person == null) ? true : false;
            String Mail     = IsPerson ? User.Person.Mail : User.mail;

            Data.User = new Domain.DTO.Notification.DTO_User
            {
                LanguageCode = User.LanguageCode,
                Mail         = Mail,
                Name         = IsPerson ? User.Person.Name : User.Name,
                Surname      = IsPerson ? User.Person.Surname : User.Sname,
                Password     = NewPassword,
                Token        = null
            };

            //Recupero messaggio
            lm.Comol.Core.Notification.Domain.dtoNotificationMessage msg =
                ServiceTemplate.GetNotificationMessage(
                    Data.User.LanguageCode,
                    ModuleTicket.UniqueCode,
                    (Int64)ModuleTicket.MailSenderActionType.externalRecover);

            if (msg == null)
            {
                return(false);
            }

            // Invio Mail.
            return(NotificationSendMail(Settings, Data, msg, Mail));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recupera un utente da una Person,
        /// SE non trova l'utente, lo crea da Person.
        /// </summary>
        /// <param name="PersonId">Id Person</param>
        /// <returns>Oggetto User</returns>
        public Domain.TicketUser UserGetfromPerson(int PersonId)
        {
            Domain.TicketUser User = Manager.GetAll <Domain.TicketUser>(tu => tu.Person != null && tu.Person.Id == PersonId).FirstOrDefault();

            if (User == null)
            {
                Domain.Enums.MailSettings settings = Domain.Enums.MailSettings.Default;
                User = UserCreateFromPerson(PersonId, settings);
            }

            return(User);
        }
Exemplo n.º 3
0
        public Token(TicketUser User, string Token)
        {
            this.User = User;
            try
            {
                Code = new System.Guid(Token);
            }
            catch
            {
                Code = System.Guid.Empty;
            }

            CreatedOn = DateTime.Now;
        }
Exemplo n.º 4
0
        public Token(TicketUser User, Boolean CreateToken)
        {
            this.User = User;
            if (CreateToken)
            {
                Code = System.Guid.NewGuid();
            }
            else
            {
                Code = System.Guid.Empty;
            }

            CreatedOn = DateTime.Now;
        }
Exemplo n.º 5
0
        public bool NotificationSendPasswordChanged(Int64 UserId, Domain.DTO.DTO_NotificationSettings Settings)
        {
            if (UserId < 0)
            {
                return(false);
            }

            Domain.TicketUser user = Manager.Get <Domain.TicketUser>(UserId);

            if (user == null || user.Id <= 0)
            {
                return(false);
            }

            return(NotificationSendPasswordChanged(user, Settings));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Invio mail per reset password - ToDo
        /// </summary>
        /// <param name="NotificationType">Tipo notifica</param>
        /// <returns></returns>
        public bool NotificationSendPasswordChanged(Domain.TicketUser User, Domain.DTO.DTO_NotificationSettings Settings)
        {
            ////Creo oggetto SETTINGS (me lo farò passare...)
            //Domain.DTO.DTO_NotificationSettings Settings = new Domain.DTO.DTO_NotificationSettings
            //{
            //    BaseUrl = "http://blablalba",
            //    DateTimeFormat = "0:dd/MM/yy H:mm:ss",
            //    LangCode = User.LanguageCode,
            //    CategoriesTemplate = "",
            //    IntCategoryType = null,
            //    IntTicketStatus = null
            //};

            //Creo oggetto DATA
            Domain.DTO.DTO_NotificationData Data = new Domain.DTO.DTO_NotificationData();
            bool   IsPerson = (User.Person == null) ? true : false;
            String Mail     = IsPerson ? User.Person.Mail : User.mail;

            Data.User = new Domain.DTO.Notification.DTO_User
            {
                LanguageCode = User.LanguageCode,
                Mail         = Mail,
                Name         = IsPerson ? User.Person.Name : User.Name,
                Surname      = IsPerson ? User.Person.Surname : User.Sname,
                Password     = "",
                Token        = null
            };

            //Recupero messaggio
            lm.Comol.Core.Notification.Domain.dtoNotificationMessage msg =
                ServiceTemplate.GetNotificationMessage(
                    Data.User.LanguageCode,
                    ModuleTicket.UniqueCode,
                    (Int64)ModuleTicket.MailSenderActionType.externalPasswordChanged);

            if (msg != null)
            {
                return(NotificationSendMail(Settings, Data, msg, Mail));
            }


            return(true);

            // Invio Mail.
        }
Exemplo n.º 7
0
        public Domain.Enums.ExternalUserPasswordErrors UserExtChangePassword(
            String OldPassword, String NewPassword, Int64 UserId)
        {
            Domain.TicketUser Usr = Manager.Get <Domain.TicketUser>(UserId);

            if (Usr == null || Usr.Id <= 0)
            {
                return(Domain.Enums.ExternalUserPasswordErrors.UserNotFound);
            }

            if (Usr.Code != AuthenticationHelper.Encrypt(OldPassword))
            {
                return(Domain.Enums.ExternalUserPasswordErrors.InvalidPassword);
            }

            Usr.UpdateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);

            Usr.Code = AuthenticationHelper.Encrypt(NewPassword);

            Manager.SaveOrUpdate <Domain.TicketUser>(Usr);

            return(Domain.Enums.ExternalUserPasswordErrors.none);
        }
Exemplo n.º 8
0
        public Domain.Enums.AccessRecoverError UserRecover(String Mail,
                                                           Domain.DTO.DTO_NotificationSettings Settings)
        {
            if (!MailCheckFormat(Mail))
            {
                return(Domain.Enums.AccessRecoverError.MailFormat);
            }

            Domain.TicketUser User = Manager.GetAll <Domain.TicketUser>(u => u.mail == Mail || u.Person != null && u.Person.Mail == Mail).FirstOrDefault();

            if (User == null || User.Id <= 0)
            {
                return(Domain.Enums.AccessRecoverError.MailNotFound);
            }

            if (!User.MailChecked)
            {
                return(Domain.Enums.AccessRecoverError.MailNotChecked);
            }

            //Setto nuova password per l'utente
            String Pwd        = PasswordGetNew();
            String EncodedPwd = AuthenticationHelper.Encrypt(Pwd);


            User.Code = EncodedPwd;
            User.UpdateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            Manager.SaveOrUpdate <Domain.TicketUser>(User);

            if (!NotificationSendRecover(User, Settings, Pwd))
            {
                return(Domain.Enums.AccessRecoverError.InternalError);
            }


            return(Domain.Enums.AccessRecoverError.none);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Ottiene il destinatario di un messaggio inviato dal sistema centrale
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public lm.Comol.Core.Mail.dtoRecipient UserGetRecipient(Int64 idUser)
        {
            Domain.TicketUser user = UserGet(idUser);
            if (user == null || user.Id <= 0)
            {
                return(null);
            }

            lm.Comol.Core.Mail.dtoRecipient recipient = new Core.Mail.dtoRecipient();

            if (user.Person != null)
            {
                recipient.DisplayName = user.Person.SurnameAndName;
                recipient.MailAddress = user.Person.Mail;
            }

            if (String.IsNullOrEmpty(recipient.DisplayName))
            {
                recipient.DisplayName = user.Sname + " " + user.Name;
                recipient.MailAddress = user.mail;
            }

            return(recipient);
        }
Exemplo n.º 10
0
 public Token(TicketUser User, Guid Token)
 {
     this.User = User;
     Code      = Token;
     CreatedOn = DateTime.Now;
 }
Exemplo n.º 11
0
        //public virtual Boolean Validated { get; set; }

        public Token()
        {
            User      = new TicketUser();
            Code      = System.Guid.Empty;
            CreatedOn = DateTime.Now;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Aggiunge un messeggio dal Manager/Resolver al Ticket indicato
        /// </summary>
        /// <param name="TicketId">Id Ticket</param>
        /// <param name="Text">Testo messaggio</param>
        /// <param name="Preview">Eventuale anteprima</param>
        /// <param name="HideToUser">Se nascondere il messaggio all'utente</param>
        /// <param name="MessageType">Tipo di messaggio</param>
        /// <param name="UpdateAccess">SE aggiornare l'accesso dell'utente al Ticket</param>
        /// <param name="UserType">Tipo utente (per messaggio e controllo)</param>
        /// <returns>Eventuali errori</returns>
        public Domain.Enums.TicketMessageSendError MessageSendMan(
            Int64 TicketId,
            String Text,
            String Preview,
            Boolean HideToUser,
            Domain.Enums.MessageType MessageType,
            Domain.Enums.MessageUserType UserType,
            Boolean UpdateAccess,
            ref Int64 NewMessageId,
            Int64 DraftId   = -1,
            Boolean IsDraft = false
            )
        {
            bool isTicketClosed = false;

            if (UserType == Domain.Enums.MessageUserType.none || UserType == Domain.Enums.MessageUserType.Partecipant ||
                CurrentPerson.TypeID == (int)UserTypeStandard.Guest ||
                CurrentPerson.TypeID == (int)UserTypeStandard.ExternalUser)
            {
                return(Domain.Enums.TicketMessageSendError.NoPermission);
            }

            if (String.IsNullOrEmpty(Text) || String.IsNullOrEmpty(Preview))
            {
                return(Domain.Enums.TicketMessageSendError.NoMessage);
            }


            Domain.TicketUser Usr = this.UserGetfromPerson(UC.CurrentUserID);
            if (Usr == null || Usr.Id <= 0)
            {
                return(Domain.Enums.TicketMessageSendError.NoPermission);
            }


            Ticket tk = Manager.Get <Ticket>(TicketId);

            if (tk == null)
            {
                return(Domain.Enums.TicketMessageSendError.TicketNotFound);
            }

            if (tk.IsDraft)
            {
                return(Domain.Enums.TicketMessageSendError.DraftTicket);
            }

            bool    IsNew = false;
            Message msg   = (from Message m in tk.Messages where m.IsDraft == true && m.Creator != null && m.Creator.Id == Usr.Id select m).FirstOrDefault();

            if (msg == null || msg.Id <= 0)
            {
                msg   = new Message();
                IsNew = true;
            }
            else
            {
                //    TEORICAMENTE NON SERVE, MA FORSE MEGLIO METTERCELO!!!
                if (DraftId != msg.Id)
                {
                    //UPDATE FILE MESSAGE ID, FROM DraftId To msgId!!!
                }
            }

            if (IsNew)
            {
                msg.CreateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            }
            else
            {
                msg.UpdateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            }

            msg.Text         = Text;
            msg.Preview      = Preview;
            msg.Creator      = Usr;
            msg.DisplayName  = "";
            msg.SendDate     = DateTime.Now;
            msg.ShowRealName = true;
            msg.Ticket       = tk;
            msg.Type         = MessageType;
            msg.UserType     = UserType;
            msg.Visibility   = !HideToUser;

            if (tk.Status == TicketStatus.closeSolved || tk.Status == TicketStatus.closeUnsolved)
            {
                isTicketClosed = true;
                msg.IsDraft    = true;
            }
            else
            {
                msg.IsDraft = IsDraft;
            }

            msg.Action   = Domain.Enums.MessageActionType.normal;
            msg.ToStatus = tk.Status;

            Domain.TicketUser usr = (from Assignment asg in tk.Assignemts where asg.AssignedTo != null orderby asg.CreatedOn select asg.AssignedTo).FirstOrDefault();

            msg.ToUser = usr;

            Domain.Category cat = (from Assignment asg in tk.Assignemts where asg.AssignedCategory != null orderby asg.CreatedOn select asg.AssignedCategory).FirstOrDefault();

            if (cat == null)
            {
                cat = tk.CreationCategory;
            }

            msg.ToCategory = cat;

            if (IsNew)
            {
                tk.Messages.Add(msg);
            }
            //else
            //    Manager.SaveOrUpdate<Message>(msg);

            tk.UpdateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            Manager.SaveOrUpdate <Ticket>(tk);

            if (UpdateAccess)
            {
                this.UserAccessUpdate(tk.Id);
            }

            NewMessageId = msg.Id;

            if (isTicketClosed)
            {
                return(TicketMessageSendError.TicketClosed);
            }

            return(Domain.Enums.TicketMessageSendError.none);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Aggiunge un messeggio DELL'UTENTE al Ticket indicato
        /// </summary>
        /// <param name="TicketId">Id Ticket</param>
        /// <param name="Text">Testo messaggio</param>
        /// <param name="Preview">Eventuale anteprima</param>
        /// <param name="ChangeStatus">Indica se dopo l'invio il ticket dovrà modificare il suo stato (riapertura/chiusura)</param>
        /// <param name="NewStatus">Il nuovo stato (se va modificato)</param>
        /// <returns>Eventuali errori</returns>
        public Domain.Enums.TicketMessageSendError MessageSendUser(
            Int64 TicketId,
            String Text,
            String Preview,
            ref Int64 MessageId,
            Boolean IsDraft = false)
        {
            //Message ChkMsg = Manager.Get<Message>(DraftId);
            //if(!ChkMsg.IsDraft)
            //    return TicketMessageSendError.none;


            bool isTicketClosed = false;

            if (String.IsNullOrEmpty(Text) || String.IsNullOrEmpty(Preview))
            {
                return(Domain.Enums.TicketMessageSendError.NoMessage);
            }

            Ticket tk = Manager.Get <Ticket>(TicketId);

            if (tk == null)
            {
                return(Domain.Enums.TicketMessageSendError.TicketNotFound);
            }

            if (tk.IsDraft)
            {
                return(Domain.Enums.TicketMessageSendError.DraftTicket);
            }

            Domain.TicketUser Usr = this.CurrentUser;

            if (tk.Owner.Id != Usr.Id)
            {
                if (!tk.IsBehalf)
                {
                    return(Domain.Enums.TicketMessageSendError.NoPermission);
                }

                if (!this.SettingPermissionGet(Domain.Enums.PermissionType.Behalf))
                {
                    return(Domain.Enums.TicketMessageSendError.NoPermission);
                }
            }


            if (!Manager.IsInTransaction())
            {
                Manager.BeginTransaction();
            }


            //this.UserGetfromPerson(UC.CurrentUserID);


            if (Usr == null || Usr.Id <= 0)
            {
                return(Domain.Enums.TicketMessageSendError.NoPermission);
            }

            bool IsNew    = false;
            bool IsBehalf = false;

            Message msg = new Message();

            if (!tk.IsBehalf || tk.Owner.Id == Usr.Id)
            {
                msg = (from Message m in tk.Messages
                       where m.IsDraft == true &&
                       m.Creator != null && m.Creator.Id == Usr.Id
                       select m).FirstOrDefault();
            }
            else
            {
                msg = (from Message m in tk.Messages
                       where m.IsDraft == true &&
                       m.CreatedBy != null && m.CreatedBy.Id == this.CurrentPerson.Id
                       select m).FirstOrDefault();
                IsBehalf = true;
            }


            if (msg == null || msg.Id <= 0)
            {
                //msg = Manager.Get<Message>(DraftId);
                //if (!msg.IsDraft)
                //{
                //    return TicketMessageSendError.none;
                //}
                //else if (msg.Ticket == null || msg.Ticket.Id != TicketId)
                //{
                msg   = new Message();
                IsNew = true;
                //}
            }
            //else
            //{

            //    //    TEORICAMENTE NON SERVE, MA FORSE MEGLIO METTERCELO!!!
            //    if (DraftId != msg.Id)
            //    {
            //        //UPDATE FILE MESSAGE ID, FROM DraftId To msgId!!!
            //    }
            //}

            if (IsNew)
            {
                msg.CreateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            }
            else
            {
                msg.UpdateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            }

            msg.Text    = Text;
            msg.Preview = Preview;
            //msg.Creator = Usr;
            msg.Creator      = tk.Owner;
            msg.DisplayName  = "";
            msg.SendDate     = DateTime.Now;
            msg.ShowRealName = true;
            msg.Ticket       = tk;
            msg.Type         = Domain.Enums.MessageType.Request;
            msg.UserType     = Domain.Enums.MessageUserType.Partecipant;
            msg.Visibility   = true;

            if (tk.Status == TicketStatus.closeSolved || tk.Status == TicketStatus.closeUnsolved)
            {
                msg.IsDraft    = true;
                isTicketClosed = true;
            }
            else
            {
                msg.IsDraft = IsDraft;
            }

            msg.Action   = Domain.Enums.MessageActionType.normal;
            msg.ToStatus = tk.Status;

            msg.IsBehalf = IsBehalf;

            Domain.TicketUser Asusr = (from Assignment asg in tk.Assignemts where asg.AssignedTo != null orderby asg.CreatedOn select asg.AssignedTo).FirstOrDefault();

            msg.ToUser = Asusr;

            Domain.Category cat = (from Assignment asg in tk.Assignemts where asg.AssignedCategory != null orderby asg.CreatedOn select asg.AssignedCategory).FirstOrDefault();

            if (cat == null)
            {
                cat = tk.CreationCategory;
            }

            msg.ToCategory = cat;

            if (IsNew)
            {
                tk.Messages.Add(msg);
            }
            else
            {
                Manager.SaveOrUpdate <Message>(msg);
            }

            MessageId = msg.Id;

            //TOLTO:
            // Verrà visualizzato nella VIEW il messaggio "Creato da..." per TUTTI i messaggi in Behalf.
            // Il messaggio di sistema verrà utilizzato SOLO per indicare che TUTTO il Ticket è passato nello stato di BEHALF.

            //if (IsBehalf)
            //{
            //    Message msgBehalf = new Message();
            //    msgBehalf.CreateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);
            //    //RIVEDERE!!!

            //    msgBehalf.Text = "Created by: " + msg.CreatedBy.SurnameAndName;
            //    msgBehalf.Preview = "";
            //    msgBehalf.Creator = this.CurrentUser;
            //    msgBehalf.DisplayName = "";
            //    msgBehalf.SendDate = DateTime.Now;
            //    msgBehalf.ShowRealName = true;
            //    msgBehalf.Ticket = tk;
            //    msgBehalf.Type = Domain.Enums.MessageType.System;
            //    msgBehalf.UserType = msg.UserType;
            //    msgBehalf.Visibility = true;

            //    msgBehalf.Action = Domain.Enums.MessageActionType.behalfMessage;
            //    msgBehalf.ToStatus = tk.Status;
            //    msgBehalf.ToUser = tk.Owner;
            //    msgBehalf.ToCategory = msg.ToCategory;
            //    msgBehalf.IsBehalf = true;
            //    //Manager.SaveOrUpdate<Message>(msgBehalf);
            //    tk.Messages.Add(msgBehalf);
            //}



            tk.UpdateMetaInfo(CurrentPerson, UC.IpAddress, UC.ProxyIpAddress);

            if (tk.Owner.Id == this.CurrentUser.Id)
            {
                tk.LastUserAccess = DateTime.Now;
            }
            else
            {
                tk.LastCreatorAccess = DateTime.Now;
            }


            Manager.SaveOrUpdate <Ticket>(tk);

            try
            {
                Manager.Commit();
            }
            catch (Exception)
            {
                Manager.RollBack();
            }

            if (isTicketClosed)
            {
                return(TicketMessageSendError.TicketClosed);
            }

            return(Domain.Enums.TicketMessageSendError.none);
        }