Exemplo n.º 1
0
        public void DeleteBasket()
        {
            var basketCommand = new BasketDeleted()
            {
                BasketID = 37
            };

            var response = basketService.DeleteBasket(basketCommand);

            Assert.AreEqual(response.Type, Common.ServiceResponseTypes.Success);
        }
Exemplo n.º 2
0
        public BasketServiceResponse <Basket> DeleteBasket(BasketDeleted ev, List <ServiceLogRecord> logRecords = null)
        {
            // Create the watch
            var sw = new Stopwatch();

            sw.Start();

            // Create a log record collection if necessary
            if (logRecords == null)
            {
                logRecords = new List <ServiceLogRecord>();
            }

            // Add log
            logRecords.Add(new ServiceLogRecord()
            {
                Type      = "DEBUG",
                TimeStamp = DateTime.Now,
                Body      = "Basket delete request received."
            });

            // Create a response object
            var response = new BasketServiceResponse <Basket>();

            #region [ Validate request ]

            // Add log
            logRecords.Add(new ServiceLogRecord()
            {
                Type      = "DEBUG",
                TimeStamp = DateTime.Now,
                Body      = "User has the required permissions. Now validating the incoming data."
            });

            // Check required data
            List <string> dataErrors = new List <string>();

            if (ev.BasketID == default(int))
            {
                dataErrors.Add("No valid Basket id found!");
            }

            if (dataErrors.Count > 0)
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "DEBUG",
                    TimeStamp = DateTime.Now,
                    Body      = dataErrors.Count + " error(s) found within the posted data! Terminating the process. Errors:" + String.Join(";", dataErrors)
                });

                // Stop the sw
                sw.Stop();

                response.Type = ServiceResponseTypes.Error;
                response.Code = ((short)HeadstoneServiceResponseCodes.Invalid_Request).ToString();
                response.PreProcessingTook = sw.ElapsedMilliseconds;
                response.Message           = "There are some errors with the incoming request data!";
                response.Errors.AddRange(dataErrors);
                response.LogRecords = logRecords;

                return(response);
            }

            #endregion


            #region [ Data manuplation ]


            #endregion


            // Stop the timer
            sw.Stop();

            // Set the pre-processing time and start the time
            response.PreProcessingTook = sw.ElapsedMilliseconds;
            sw.Start();


            #region [ Load reseller application ]


            Basket Basket = _basketServiceBase.Get(r => r.BasketID == ev.BasketID).Result.FirstOrDefault();

            if (Basket == null)
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "DEBUG",
                    TimeStamp = DateTime.Now,
                    Body      = "No Basket found with the given id!"
                });

                // Stop the sw
                sw.Stop();

                response.Type        = ServiceResponseTypes.Error;
                response.Code        = ((short)HeadstoneServiceResponseCodes.Invalid_Request).ToString();
                response.ServiceTook = sw.ElapsedMilliseconds;
                response.Message     = "No Basket found with the given id!";
                response.Errors.Add("No Basket found with the given id!");
                response.LogRecords = logRecords;

                return(response);
            }
            #endregion

            #region [ Delete reseller application ]

            // Add log
            logRecords.Add(new ServiceLogRecord()
            {
                Type      = "DEBUG",
                TimeStamp = DateTime.Now,
                Body      = "Deleting Basket."
            });

            // Delete the billing info
            var baseServiceResponse = _basketServiceBase.Delete(Basket);

            if (baseServiceResponse.Type != Headstone.Framework.Models.ServiceResponseTypes.Success)
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "ERROR",
                    TimeStamp = DateTime.Now,
                    Body      = "There was an error while deleting the Basket!"
                });

                // Stop the sw
                sw.Stop();

                response.Type        = ServiceResponseTypes.Error;
                response.Code        = ((short)HeadstoneServiceResponseCodes.General_Exception).ToString();
                response.ServiceTook = sw.ElapsedMilliseconds;
                response.Message     = "There was an error while deleting the Basket!";
                response.Errors.Add("There was an error while deleting the Basket!");
                response.Errors.AddRange(baseServiceResponse.Errors);
                response.LogRecords = logRecords;

                return(response);
            }
            else
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "DEBUG",
                    TimeStamp = DateTime.Now,
                    Body      = string.Format("Basket successfuly deleted. BasketID:{0}",
                                              Basket.BasketID)
                });

                // Add the new object to the result
                response.Result.Add(Basket);

                // Set the role id
                response.BasketID = Basket.BasketID;
            }

            #endregion

            // Stop the sw
            sw.Stop();

            response.Type        = ServiceResponseTypes.Success;
            response.Code        = ((short)HeadstoneServiceResponseCodes.Request_Successfuly_Completed).ToString();
            response.ServiceTook = sw.ElapsedMilliseconds;
            response.Message     = string.Format("Basket successfuly deleted. BasketID:{0}",
                                                 Basket.BasketID);
            response.LogRecords = logRecords;

            return(response);
        }