示例#1
0
 /// <summary>
 /// Обновление объявления
 /// </summary>
 /// <param name="updatingAnnouncement"></param>
 /// <returns></returns>
 public RepositoryResult UpdateAnnouncement(IAnnouncement updatingAnnouncement)
 {
     if (updatingAnnouncement == null)
     {
         return(new RepositoryResult {
             Status = ActionStatus.Error, Message = $"Не указано обновляемое объявление.", Entity = null
         });
     }
     updatingAnnouncement.LastEdited = DateTime.Now;
     try
     {
         var session = _sessionFactory.OpenSession();
         using (session.BeginTransaction())
         {
             session.Update(updatingAnnouncement);
             session.Transaction.Commit();
         }
         var updatedAnnouncement = session.Get <IAnnouncement>(updatingAnnouncement.Id);
         session.Close();
         return(updatedAnnouncement == updatingAnnouncement
         ? new RepositoryResult {
             Status = ActionStatus.Success, Message = $"Объявление ({updatingAnnouncement.Id}) успешно обновлено.", Entity = new IAnnouncement[] { updatedAnnouncement }
         }
         : new RepositoryResult {
             Status = ActionStatus.Warning, Message = $"Не удалось обновить данные объявления {updatingAnnouncement.Id}.", Entity = null
         });
     }
     catch (Exception ex)
     {
         return(new RepositoryResult {
             Status = ActionStatus.Fatal, Message = $"При обновлении данных объявления ({updatingAnnouncement.Id}) произошла непредвиденная ошибка репозитория. Исключение: {ex.Message}", Entity = null
         });
     }
 }
示例#2
0
        /// <summary>
        /// Создание объявления
        /// </summary>
        /// <param name="savingEntity"></param>
        /// <returns></returns>
        public RepositoryResult CreateAnnouncement(IAnnouncement savingEntity)
        {
            if (savingEntity == null)
            {
                return(new RepositoryResult {
                    Status = ActionStatus.Error, Message = $"Не указано создаваемое объявление.", Entity = null
                });
            }
            savingEntity.LastEdited   = DateTime.Now;
            savingEntity.CreationDate = savingEntity.LastEdited;
            savingEntity.Id           = Guid.NewGuid();
            try
            {
                var session = _sessionFactory.OpenSession();
                using (session.BeginTransaction())
                {
                    if (savingEntity is CandidateBase)
                    {
                        session.Save(savingEntity);
                    }

                    if (savingEntity is VacancyBase)
                    {
                        var query = session.CreateSQLQuery("AddVacancy :@id, :@announcementId, :@creationDate, :@lastEdited, :@lastEditorId, :@type, :@isBlocked, :@name, :@about, :@employment, :@requirement, :@isOpen, :@validDay, :@salary");
                        query.SetGuid("@id", savingEntity.Id);
                        query.SetGuid("@announcementId", savingEntity.Creator.Id);
                        query.SetDateTime("@creationDate", savingEntity.CreationDate);
                        query.SetDateTime("@lastEdited", savingEntity.LastEdited);
                        query.SetGuid("@lastEditorId", savingEntity.LastEditor.Id);
                        query.SetInt32("@type", (int)savingEntity.Type);
                        query.SetBoolean("@isBlocked", savingEntity.IsBlocked);
                        query.SetString("@name", (savingEntity as VacancyBase).Name);
                        query.SetString("@about", (savingEntity as VacancyBase).About);
                        query.SetInt32("@employment", (int)(savingEntity as VacancyBase).Employment);
                        query.SetString("@requirement", (savingEntity as VacancyBase).Requirement);
                        query.SetBoolean("@isOpen", (savingEntity as VacancyBase).IsOpen);
                        query.SetDateTime("@validDay", (savingEntity as VacancyBase).ValidDay);
                        query.SetInt32("@salary", (savingEntity as VacancyBase).Salary);
                        query.ExecuteUpdate();
                    }
                    session.Transaction.Commit();
                }
                var savedEntity = session.Get <IAnnouncement>(savingEntity.Id);
                session.Close();
                return(savedEntity != null
                ? new RepositoryResult {
                    Status = ActionStatus.Success, Message = $"Объявление ({savingEntity.Id}) успешно добавлено.", Entity = new IAnnouncement[] { savedEntity }
                }
                : new RepositoryResult {
                    Status = ActionStatus.Warning, Message = $"Не удалось добавить объявление {savedEntity.Id}.", Entity = null
                });
            }
            catch (Exception ex)
            {
                return(new RepositoryResult {
                    Status = ActionStatus.Fatal, Message = $"При обновлении данных объявления ({savingEntity.Id}) произошла непредвиденная ошибка репозитория. Исключение: {ex.Message}", Entity = null
                });
            }
        }
示例#3
0
        /// <summary>
        /// Used for commands so that a user may view or play an <see cref="IAnnouncement"/> based off of the given arguments.
        /// </summary>
        /// <param name="announcement">The <see cref="IAnnouncement"/> to view or play.</param>
        /// <param name="command">The command that the request originated from.</param>
        /// <param name="argument">The player given request of action.</param>
        /// <param name="response">The message to send back to the player.</param>
        /// <returns>Whether the command executed successfully.</returns>
        public static bool ViewOrPlay(IAnnouncement announcement, string command, string argument, out string response)
        {
            switch (argument)
            {
            case "p":
            case "play":
                response = "Playing announcement.";
                PlayAnnouncement(announcement);
                return(true);

            case "v":
            case "view":
                response = announcement.Message;
                return(true);

            default:
                response = $"Syntax: ca {command} (v/p)";
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// Plays a CASSIE announcement based off of the configuration of a <see cref="IAnnouncement"/>.
        /// </summary>
        /// <param name="announcement">The announcement to play.</param>
        /// <param name="overrideMessage">The message to override the <see cref="IAnnouncement.Message"/>. Ignored if null or empty.</param>
        public static void PlayAnnouncement(IAnnouncement announcement, string overrideMessage = null)
        {
            string message = announcement.Message;

            if (!string.IsNullOrEmpty(overrideMessage))
            {
                message = overrideMessage;
            }

            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            message = GetVariableMessage(message);
            if (announcement.IsGlitchy)
            {
                Cassie.DelayedGlitchyMessage(message, announcement.Delay, announcement.GlitchChance * 0.01f, announcement.JamChance * 0.01f);
            }
            else
            {
                Cassie.DelayedMessage(message, announcement.Delay, isNoisy: announcement.IsNoisy);
            }
        }
 /// <summary>
 /// Returns a value which indicates whether the announcement's message is null or empty.
 /// </summary>
 /// <param name="announcement">The announcement to check.</param>
 /// <returns>Whether the <see cref="IAnnouncement.Message"/> was null.</returns>
 public static bool IsNullOrEmpty(this IAnnouncement announcement) => string.IsNullOrEmpty(announcement.Message);