public void UpdateCampaignStatus()
        {
            var campaignCommand = new CampaignUpdated()
            {
                CampaignID = 15,
                Status     = Framework.Models.EntityStatus.Passive
            };

            var response = campaingService.UpdateCampaignStatus(campaignCommand);

            Assert.AreEqual(response.Type, Common.ServiceResponseTypes.Success);
        }
        public void UpdateCampaign()
        {
            var campaignCommand = new CampaignUpdated()
            {
                CampaignID            = 15,
                RelatedDataEntityName = "UpdateTestEntityName",
                RelatedDataEntityID   = 2,
                Name             = "UpdateTestName",
                ShortDescription = "UpdateTestSDescription",
                LongDescription  = "UpdateTestLDescription",
                DiscountType     = DiscountType.Amount,
                DiscountAmount   = 20
            };

            var response = campaingService.UpdateCampaign(campaignCommand);

            Assert.AreEqual(response.Type, Common.ServiceResponseTypes.Success);
        }
        public CampaignServiceResponse <Campaign> UpdateCampaignStatus(CampaignUpdated 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      = "Campaign status update request received."
            });

            // Create a response object
            var response = new CampaignServiceResponse <Campaign>();

            #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.CampaignID == default(int))
            {
                dataErrors.Add("No valid Campaign 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 the reseller application ]

            Campaign Campaign = _CampaignServiceBase.Get(r => r.CampaignID == ev.CampaignID).Result.FirstOrDefault();

            if (Campaign == null)
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "DEBUG",
                    TimeStamp = DateTime.Now,
                    Body      = "No Campaign 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 Campaign found with the given id!";
                response.Errors.Add("No Campaign found with the given id!");
                response.LogRecords = logRecords;

                return(response);
            }

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

            // Update the Campaign status
            Campaign.Status  = ev.Status;
            Campaign.Updated = DateTime.UtcNow;


            // Add log
            logRecords.Add(new ServiceLogRecord()
            {
                Type      = "DEBUG",
                TimeStamp = DateTime.UtcNow,
                Body      = "Campaign status updated."
            });

            #endregion

            #region [ Save reseller application ]

            // Save the address
            var baseServiceResponse = _CampaignServiceBase.Update(Campaign);

            if (baseServiceResponse.Type != Headstone.Framework.Models.ServiceResponseTypes.Success)
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "DEBUG",
                    TimeStamp = DateTime.UtcNow,
                    Body      = "There was an error while updating the Campaign status!"
                });

                // 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 updating Campaign!";
                response.Errors.AddRange(baseServiceResponse.Errors);
                response.LogRecords = logRecords;

                return(response);
            }
            else
            {
                // Add log
                logRecords.Add(new ServiceLogRecord()
                {
                    Type      = "DEBUG",
                    TimeStamp = DateTime.UtcNow,
                    Body      = string.Format("Campaign status successfuly updated. CampaignId:{0}",
                                              Campaign.CampaignID)
                });

                // Set the output information
                response.Result.Add(Campaign);
                response.CampaignID = Campaign.CampaignID;
            }

            #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("Campaign status successfuly updated. CampaignId:{0}",
                                                 Campaign.CampaignID);
            response.LogRecords = logRecords;

            return(response);
        }