Exemple #1
0
        public async Task <IActionResult> Delete(string id)
        {
            ObjectId oId   = new ObjectId(id);
            Movies   movie = collection.Find(e => e.MovieId
                                             == oId).FirstOrDefault();
            string blobstorageconnection            = "DefaultEndpointsProtocol=https;AccountName=bmsappstorage;AccountKey=o+npBZaJ2WVWjXdpDLiWnmO5I/H6yXJhptrVipbGz+TyhiAdvyL2c0yJbAYaXvy6ew2SyNmkq7/Rfcwoiu6K4w==;EndpointSuffix=core.windows.net";
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);
            CloudBlobClient     cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();
            string             strContainerName     = "blobcontainer";
            CloudBlobContainer cloudBlobContainer   = cloudBlobClient.GetContainerReference(strContainerName);

            string[] parts    = movie.imageUrl.Split('/');
            string   fileName = "";

            if (parts.Length > 0)
            {
                fileName = parts[parts.Length - 1];
            }
            else
            {
                fileName = movie.imageUrl;
            }

            var blob = cloudBlobContainer.GetBlobReference(fileName);
            await blob.DeleteIfExistsAsync();

            TheatreMovie theatreMov = theatreMovie.Find(e => e.MID
                                                        == oId).FirstOrDefault();

            collection.DeleteOne <Movies>(e => e.MovieId == oId);
            theatreMovie.DeleteOne <TheatreMovie>(e => e.TheatreMovieID == theatreMov.TheatreMovieID);
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Delete(string id)
        {
            ObjectId oId   = new ObjectId(id);
            Movies   movie = collection.Find(e => e.MovieId
                                             == oId).FirstOrDefault();

            #region  blob delete


            string blobstorageconnection            = "DefaultEndpointsProtocol=https;AccountName=bmsappstorage1;AccountKey=XBK+O+GWuft1gw8a/nPwCik0WK3dJmZARk6bX99Ltmu4w2ZvkkTZXvSLf9QdflafDkzI70Ipr3KAeRKduGbudg==;EndpointSuffix=core.windows.net";
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);
            CloudBlobClient     cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();
            string             strContainerName     = "blobcontainer";
            CloudBlobContainer cloudBlobContainer   = cloudBlobClient.GetContainerReference(strContainerName);
            string[]           parts    = movie.imageUrl.Split('/');
            string             fileName = "";

            if (parts.Length > 0)
            {
                fileName = parts[parts.Length - 1];
            }
            else
            {
                fileName = movie.imageUrl;
            }

            var blob = cloudBlobContainer.GetBlobReference(fileName);
            await blob.DeleteIfExistsAsync();

            #endregion
            TheatreMovie theatreMov = theatreMovie.Find(e => e.MID
                                                        == oId).FirstOrDefault();

            collection.DeleteOne <Movies>(e => e.MovieId == oId);
            theatreMovie.DeleteOne <TheatreMovie>(e => e.TheatreMovieID == theatreMov.TheatreMovieID);
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public async Task <IActionResult> Book(MovieUser u, string id)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            u.userDetails.uid = userId;


            var          tmov = theatreMovie.Find(FilterDefinition <TheatreMovie> .Empty).ToList();
            TheatreMovie tm   = tmov.Where(p => p.TheatreMovieID == new MongoDB.Bson.ObjectId(id)).FirstOrDefault();

            if (u.userDetails.Seat <= tm.seat)
            {
                user.InsertOne(u.userDetails);
                tm.seat = tm.seat - u.userDetails.Seat;
                var filter = Builders <TheatreMovie> .Filter.Eq("TheatreMovieID", new ObjectId(id));

                var updateDef = Builders <TheatreMovie> .Update.Set("seat", tm.seat);

                theatreMovie.UpdateOne(filter, updateDef);
                if (CreateQueue(userId))
                {
                    // Instantiate a QueueClient which will be used to create and manipulate the queue
                    QueueClient queueClient = new QueueClient(connectionString, userId);

                    // Create the queue if it doesn't already exist
                    queueClient.CreateIfNotExists();

                    if (queueClient.Exists())
                    {
                        // Send a message to the queue
                        queueClient.SendMessage("success");
                        PeekedMessage[] peekedMessage = queueClient.PeekMessages();
                        if (peekedMessage.Length == 1)
                        {
                            string mseFromQ = peekedMessage[0].MessageText;
                            if (mseFromQ == "success")
                            {
                                Random generator = new Random();
                                string msg       = "Hey  <b>" + u.userDetails.name + "</b>," + Environment.NewLine + "<br/>" + "Your booking is confirmed now of your " + u.userDetails.Seat + " seats.<br/>" + Environment.NewLine + "Your booking Id is " + generator.Next(0, 999999).ToString("D6") + "<br/>" + Environment.NewLine + "Thanks,<br/>" + Environment.NewLine + "<b>BMS</b>";
                                await callSecondService(u.userDetails, msg);

                                queueClient.Delete();
                            }
                        }
                        else if (peekedMessage.Length > 1)
                        {
                        }
                        else
                        {
                            string msg = "Hey  <b>" + u.userDetails.name + "</b>," + Environment.NewLine + "<br/>" + "sorry for inconvenience." + " <br/>" + "Thanks,<br/>" + Environment.NewLine + "<b>BMS</b>";
                            await callSecondService(u.userDetails, msg);
                        }
                    }
                }
                return(RedirectToAction("index"));
            }

            else
            {
                Random generator = new Random();
                string msg       = "Hey  <b>" + u.userDetails.name + "</b>," + Environment.NewLine + "<br/>" + "sorry for inconvenience." + " <br/>" + "Thanks,<br/>" + Environment.NewLine + "<b>BMS</b>";
                await callSecondService(u.userDetails, msg);

                return(RedirectToAction("index"));
            }


            return(RedirectToAction("index"));
        }
Exemple #4
0
        public async Task <IActionResult> CreateAsync(Movies movie)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string webRootPath = _hostEnvironment.WebRootPath;
                    var    files       = HttpContext.Request.Form.Files;

                    if (files.Count > 0)
                    {
                        string fileName   = Guid.NewGuid().ToString();
                        var    uploads    = Path.Combine(webRootPath, @"movies");
                        var    extenstion = Path.GetExtension(files[0].FileName);

                        #region blob
                        string blobstorageconnection = "DefaultEndpointsProtocol=https;AccountName=bmsappstorage;AccountKey=o+npBZaJ2WVWjXdpDLiWnmO5I/H6yXJhptrVipbGz+TyhiAdvyL2c0yJbAYaXvy6ew2SyNmkq7/Rfcwoiu6K4w==;EndpointSuffix=core.windows.net";

                        byte[] dataFiles;
                        // Retrieve storage account from connection string.
                        CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);
                        // Create the blob client.
                        CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
                        // Retrieve a reference to a container.
                        CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("blobcontainer");

                        BlobContainerPermissions permissions = new BlobContainerPermissions
                        {
                            PublicAccess = BlobContainerPublicAccessType.Blob
                        };
                        string systemFileName = fileName + extenstion;
                        await cloudBlobContainer.SetPermissionsAsync(permissions);

                        await using (var target = new MemoryStream())
                        {
                            files[0].CopyTo(target);
                            dataFiles = target.ToArray();
                        }
                        // This also does not make a service call; it only creates a local object.
                        CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(systemFileName);
                        await cloudBlockBlob.UploadFromByteArrayAsync(dataFiles, 0, dataFiles.Length);


                        #endregion


                        string mimeType = files[0].ContentType;
                        byte[] fileData = new byte[files[0].Length];

                        //BlobStorageService objBlobService = new BlobStorageService();

                        //movie.imageUrl = objBlobService.UploadFileToBlob(fileName + extenstion, fileData, mimeType);
                        movie.imageUrl = cloudBlockBlob.Uri.AbsoluteUri;
                        //movie.imageUrl = @"\movies\" + fileName + extenstion;
                    }

                    Theatre t = theatre.Find(FilterDefinition <Theatre> .Empty).FirstOrDefault();           //Get Issuer Collection list


                    collection.InsertOne(movie);         //To post the issuer object
                    TheatreMovie tm = new TheatreMovie()
                    {
                        MID  = movie.MovieId,
                        TID  = t.TheatreID,
                        seat = t.Seat
                    };
                    theatreMovie.InsertOne(tm);
                }
                catch (Exception)
                {
                    ModelState.AddModelError(string.Empty, "Please try again later.");
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View());
        }