public ActionResult DoDelete(StoreNotificationModel model)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(Json(new ResponseMessageModel
                    {
                        HasError = true,
                        Title = ResShared.TITLE_REGISTER_FAILED,
                        Message = ResShared.ERROR_INVALID_MODEL
                    }));
                }

                using (var repository = new NotificationRepository())
                {
                    using (var trans = repository.Db.Database.BeginTransaction())
                    {
                        var response = repository.DeleteNotification(model);
                        trans.Commit();
                        return(Json(response));
                    }
                }
            }
            catch (Exception ex)
            {
                SharedLogger.LogError(ex);
                return(Json(new ResponseMessageModel
                {
                    HasError = true,
                    Title = ResShared.TITLE_REGISTER_FAILED,
                    Message = ResShared.ERROR_UNKOWN
                }));
            }
        }
        public ResponseMessageModel DeleteNotification(StoreNotificationModel model)
        {
            var today        = DateTime.Today;
            var storeMessage = Db.StoreMessageDate.SingleOrDefault(e => e.FranchiseStoreId == model.FranchiseStoreId &&
                                                                   (e.IsIndefinite || e.DateApplied == today) &&
                                                                   e.CategoryMessageId == model.CategoryMessageId &&
                                                                   e.StoreMessage.Message == model.Message);

            if (storeMessage == null)
            {
                return new ResponseMessageModel
                       {
                           HasError = true,
                           Message  = "La notificación que desea eliminar ya no existe, por favor refresque su navegador para ver las notificaciones activas para el día actual"
                       }
            }
            ;

            Db.StoreMessageDate.Remove(storeMessage);
            Db.SaveChanges();

            return(new ResponseMessageModel {
                HasError = false, Data = model.Message
            });
        }
        private int GetStoreMessageIdByMessageIfExists(StoreNotificationModel model)
        {
            var storeMessageId =
                Db.StoreMessage.Where(e => e.Message == model.Message).Select(e => e.StoreMessageId).SingleOrDefault();

            return(storeMessageId);
        }
        public ResponseMessageModel InsertNotification(StoreNotificationModel model, string userId)
        {
            var storeMessageId = GetStoreMessageIdByMessageIfExists(model);

            var today = DateTime.Today;

            if (storeMessageId == SharedConstants.DEFAULT_INT_VALUE)
            {
                storeMessageId = InsertStoreMessage(model.Message, userId);
            }
            else
            {
                if (IsAnyNotificationForDate(today, storeMessageId, model))
                {
                    return(new ResponseMessageModel
                    {
                        HasError = true,
                        Message = "La notificación ya fue agregada para este día, para la categoría y la sucursal seleccionada"
                    });
                }
            }

            var storeMessageDate = new StoreMessageDate
            {
                CategoryMessageId = model.CategoryMessageId,
                DateApplied       = today,
                FranchiseStoreId  = model.FranchiseStoreId,
                StoreMessageId    = storeMessageId,
                IsIndefinite      = model.IsIndefinite,
                Resource          = model.Resource,
                UserIdIns         = userId
            };

            Db.StoreMessageDate.Add(storeMessageDate);
            Db.SaveChanges();

            return(new ResponseMessageModel
            {
                HasError = false,
                Data = model.Message
            });
        }
Пример #5
0
        public ListStoreNotificationModels GetNotification(int tenantID, int userID)
        {
            List <StoreNotificationModel> ListstoreNotificationModel = new List <StoreNotificationModel>();

            ListStoreNotificationModels storeNotificationModels = new ListStoreNotificationModels();
            DataSet      ds  = new DataSet();
            MySqlCommand cmd = new MySqlCommand();

            try
            {
                conn.Open();
                cmd.Connection = conn;

                MySqlCommand cmd1 = new MySqlCommand("SP_GetStoreNotifications", conn);
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.AddWithValue("@Tenant_ID", tenantID);
                cmd1.Parameters.AddWithValue("@User_ID", userID);

                MySqlDataAdapter da = new MySqlDataAdapter();
                da.SelectCommand = cmd1;
                da.Fill(ds);

                if (ds != null && ds.Tables[0] != null)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        StoreNotificationModel storeNotificationModel = new StoreNotificationModel();
                        storeNotificationModel.NotificationCount = ds.Tables[0].Rows[i]["NotificationCount"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["NotificationCount"]);
                        storeNotificationModel.AlertID           = ds.Tables[0].Rows[i]["AlertID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["AlertID"]);
                        storeNotificationModel.NotificationName  = ds.Tables[0].Rows[i]["NotificationName"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["NotificationName"]);
                        int alertID = Convert.ToInt32(ds.Tables[0].Rows[i]["AlertID"]);
                        storeNotificationModel.CustomTaskNotificationModels = ds.Tables[1].AsEnumerable().Where(x => Convert.ToInt32(x.Field <int>("AlertID")).
                                                                                                                Equals(alertID)).Select(x => new CustomTaskNotificationModel()
                        {
                            NotificationID      = Convert.ToInt32(x.Field <int>("NotificationID")),
                            AlertID             = Convert.ToInt32(x.Field <int>("AlertID")),
                            NotificatonTypeID   = Convert.ToInt32(x.Field <int>("NotificatonTypeID")),
                            NotificatonType     = Convert.ToInt32(x.Field <int>("NotificatonType")),
                            NotificatonTypeName = x.Field <object>("NotificatonTypeName") == DBNull.Value ? string.Empty : Convert.ToString(x.Field <object>("NotificatonTypeName"))
                        }).ToList();
                        ListstoreNotificationModel.Add(storeNotificationModel);
                        if (ListstoreNotificationModel.Count > 0)
                        {
                            storeNotificationModels.StoreNotificationModel = ListstoreNotificationModel;
                            storeNotificationModels.NotiCount = ListstoreNotificationModel.Select(x => x.NotificationCount).Sum();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (ds != null)
                {
                    ds.Dispose();
                }
                conn.Close();
            }

            return(storeNotificationModels);
        }
 private bool IsAnyNotificationForDate(DateTime date, int storeMessageId, StoreNotificationModel model)
 {
     return(Db.StoreMessageDate.Any(e => e.FranchiseStoreId == model.FranchiseStoreId &&
                                    e.StoreMessageId == storeMessageId &&
                                    e.CategoryMessageId == model.CategoryMessageId && (e.IsIndefinite || e.DateApplied == date)));
 }