Esempio n. 1
0
        public ActionResult ShareSong(int TrackId, int[] CustomerIds, string Message = "", string RemoteTrackId = "")
        {
            if (CustomerIds == null)
            {
                return(Json(new { Success = false, Message = "Failed" }));
            }

            //check if song exists
            var song = _songService.GetById(TrackId);

            if (song == null)
            {
                //song is not there. let's first import the song
                if (!string.IsNullOrWhiteSpace(RemoteTrackId))
                {
                    //we need to create a new song now
                    var remoteSong = _artistPageApiService.GetRemoteSong(RemoteTrackId);
                    if (remoteSong == null)
                    {
                        return(Json(new { Success = false, Message = "Failed" }));
                    }

                    song = SaveRemoteSongToDB(remoteSong);
                }
                else
                {
                    return(Json(new { Success = false, Message = "InvalidId" }));
                }
            }
            if (_workContext.CurrentCustomer.IsRegistered())
            {
                foreach (var CustomerId in CustomerIds.Distinct())
                {
                    {
                        var sharedSong = new SharedSong()
                        {
                            CustomerId = CustomerId,
                            SenderId   = _workContext.CurrentCustomer.Id,
                            SongId     = song.Id,
                            Message    = Message,
                            SharedOn   = DateTime.Now
                        };
                        _sharedSongService.Insert(sharedSong);
                        //send the notification to the customer
                        var customer = _customerService.GetCustomerById(CustomerId);
                        _mobsocialMessageService.SendSomeoneSentYouASongNotification(customer, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id);
                    }
                }
                return(Json(new { Success = true }));
            }
            else
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }
        }