public bool offerCodeIsOwnedByUserCompany(OfferCode offerCode)
        {
            OfferService offerService = new OfferService();

            if (offerCode != null)
            {
                Offer offer = new Offer();
                offer = offerService.GetOffer(offerCode.OfferId);
                var company = UserCompany;
                if (offer != null && offer.CompanyId != company.Id)
                {
                    offerCode = null;
                }
                if (offerCode == null)
                {
                    //offer ain't there.
                    return(false);
                }
                //if we got this far, should be valid.
                return(true);
            }
            //if offer code is null
            else
            {
                return(false);
            }
        }
        public ActionResult CreateBulk(OfferCodeViewModel model)
        {
            if (String.IsNullOrWhiteSpace(model.Codes))
            {
                ModelState.AddModelError("Codes", "Codes are required");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var offerService = new OfferService();
            var offerCode    = new OfferCode();

            List <OfferCode> codesList = new List <OfferCode>();
            string           codes     = model.Codes;

            string[] splitCodes = codes.Split(null);
            foreach (var item in splitCodes)
            {
                if (String.IsNullOrEmpty(item))
                {
                    continue;
                }
                //Handle split and save each code accordingly
                offerCode.Code    = item;
                offerCode.OfferId = model.OfferId;
                offerCode.Id      = model.Id;
                offerService.SaveOfferCode(offerCode);
            }
            model.SuccessMessage = "Success - Offer Codes saved.";
            return(RedirectToAction("List", new { offerId = model.OfferId }));
        }
Exemple #3
0
        public void UpdateOfferCode(OfferCode offerCode)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@Id", offerCode.Id, dbType: DbType.Int32, direction: ParameterDirection.Input);
            parameters.Add("@Code", offerCode.Code, dbType: DbType.String, direction: ParameterDirection.Input);

            SqlConnection.Execute("OfferCode_Update", parameters, commandType: CommandType.StoredProcedure);
        }
Exemple #4
0
 public void Save(OfferCode offerCode)
 {
     if (offerCode.Id == 0)
     {
         offerCode.Id = new Data().CreateOfferCode(offerCode);
     }
     else
     {
         new Data().UpdateOfferCode(offerCode);
     }
 }
Exemple #5
0
        //OfferCode methods

        public void SaveOfferCode(OfferCode OfferCode)
        {
            try
            {
                _codeRepo.Save(OfferCode);
            }
            catch (Exception ex)
            {
                _logger.Error("Error during OfferService.SaveOfferCode()", ex);
                throw;
            }
        }
Exemple #6
0
        public int CreateOfferCode(OfferCode offerCode)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output);
            parameters.Add("@OfferId", offerCode.OfferId, dbType: DbType.String, direction: ParameterDirection.Input);
            parameters.Add("@Code", offerCode.Code, dbType: DbType.String, direction: ParameterDirection.Input);
            parameters.Add("@ClaimingUser", offerCode.ClaimingUser, dbType: DbType.String, direction: ParameterDirection.Input);

            SqlConnection.Execute("OfferCode_Add", parameters, commandType: CommandType.StoredProcedure);
            int id = parameters.Get <int>("@Id");

            return(id);
        }
Exemple #7
0
        public BaseEntity BuildObject(Dictionary <string, object> row)
        {
            var offerCode = new OfferCode
            {
                Id          = GetIntValue(row, DB_COL_ID),
                Code        = GetStringValue(row, DB_COL_CODE),
                Description = GetStringValue(row, DB_COL_DESCRIPTION),
                Value       = GetDecimalValue(row, DB_COL_VALUE),
                Product     = GetIntValue(row, DB_COL_CODE),
                Provider    = GetIntValue(row, DB_COL_ID_PROVIDER),
                Active      = GetBooleanValue(row, DB_COL_ACTIVE),
            };

            return(offerCode);
        }
Exemple #8
0
        // GET api/Proyect/State
        public IHttpActionResult Get(bool active)
        {
            try
            {
                var mng       = new OfferCodeManager();
                var offerCode = new OfferCode
                {
                    Active = active
                };

                apiResp.Data = mng.RetrieveByState(offerCode);

                return(Ok(apiResp));
            }
            catch (BussinessException bex)
            {
                return(InternalServerError(new Exception(bex.ExceptionId + "-" + bex.AppMessage.Message)));
            }
        }
Exemple #9
0
        // DELETE
        public IHttpActionResult Delete(OfferCode proyect)
        {
            try
            {
                var mng = new OfferCodeManager();
                mng.Delete(proyect);

                apiResp = new ApiResponse
                {
                    Message = "Action was executed."
                };

                return(Ok(apiResp));
            }
            catch (BussinessException bex)
            {
                return(InternalServerError(new Exception(bex.ExceptionId + "-" + bex.AppMessage.Message)));
            }
        }
        public OfferCode RetrieveById(OfferCode offerCode)
        {
            OfferCode p = null;

            try
            {
                p = crudProduct.Retrieve <OfferCode>(offerCode);
                if (p == null)
                {
                    throw new BussinessException(4);
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.GetInstance().Process(ex);
            }

            return(p);
        }
Exemple #11
0
        // POST
        public IHttpActionResult Post(OfferCode offerCode)
        {
            try
            {
                var mng = new OfferCodeManager();
                offerCode.Active = true;
                mng.Create(offerCode);

                apiResp = new ApiResponse
                {
                    Message = "Action was executed."
                };

                return(Ok(apiResp));
            }
            catch (BussinessException bex)
            {
                return(InternalServerError(new Exception(bex.ExceptionId + "-" + bex.AppMessage.Message)));
            }
        }
 public void Delete(OfferCode offerCode)
 {
     crudProduct.Delete(offerCode);
 }
 public void Update(OfferCode offerCode)
 {
     crudProduct.Update(offerCode);
 }
 public List <OfferCode> RetrieveByState(OfferCode offerCode)
 {
     return(crudProduct.RetrieveByState <OfferCode>(offerCode));
 }
 public void Create(OfferCode offerCode)
 {
     crudProduct.Create(offerCode);
 }
Exemple #16
0
        public void OfferCodeCRUDUsingToken()
        {
            //create (offer)
            var Offer           = new Offer();
            var testTitle       = "Sword Sale";
            var testDescription = "90% off these real dull swords!";
            var testUrl         = "fakeurl.bamazon.swords/";
            var testCategory    = "Weapons";
            var testCompanyId   = RandomInteger();

            Offer.Title       = testTitle;
            Offer.Description = testDescription;
            Offer.Url         = testUrl;
            Offer.Category    = testCategory;
            Offer.CompanyId   = testCompanyId;

            //create (offercode)
            var OfferCode = new OfferCode();
            var testCode  = "ABCDEF" + RandomDigits();

            OfferCode.OfferId = Offer.Id;
            OfferCode.Code    = testCode;

            var OfferService = new OfferService();

            OfferService.SaveOffer(Offer);
            Assert.IsTrue(Offer.Id != 0);

            OfferService.SaveOfferCode(OfferCode);
            Assert.IsTrue(OfferCode.Id != 0);

            var offer1 = OfferService.GetOffer(Offer.Id);

            // get it, verify it's there (offer)
            var OfferToken = offer1.Token;
            var Offer2     = OfferService.GetOfferByToken(OfferToken);

            Assert.IsNotNull(Offer2);

            // get it, verify it's there (offercode)
            var OfferCodeId = OfferCode.Id;
            var OfferCode2  = OfferService.GetOfferCode(OfferCodeId);

            Assert.IsNotNull(OfferCode2);

            // verify property values (offer)
            Assert.AreEqual(Offer2.Title, testTitle);
            Assert.AreEqual(Offer2.Description, testDescription);
            Assert.AreEqual(Offer2.Url, testUrl);
            Assert.AreEqual(Offer2.Category, testCategory);
            Assert.AreEqual(Offer2.CompanyId, testCompanyId);

            //verify property values (offercode)
            Assert.AreEqual(OfferCode2.OfferId, OfferCode.OfferId);
            Assert.AreEqual(OfferCode2.Code, testCode);

            //update offercode
            var testCode2 = "XYZ123" + RandomDigits();

            OfferCode2.Code = testCode2;
            OfferService.SaveOfferCode(OfferCode2);

            // get it again, verify property values
            var OfferCode3 = OfferService.GetOfferCode(OfferCode2.Id);

            Assert.AreEqual(testCode2, OfferCode3.Code);

            //delete it
            OfferService.DeleteOfferCode(OfferCodeId);
            OfferCode3 = OfferService.GetOfferCode(OfferCodeId);
            Assert.IsNull(OfferCode3);
            //var Offer = new Offer();
            //var testTitle = "Bracelets";
            //var testDescription = "70% off this gold jewelry shining so bright! " +
            //    "Goes great with strawberry champagne!";
            //var testUrl = "fakeurl.bamazon.whatilike/";
            //var testCategory = "Jewelry";

            //var testCompanyId = RandomInteger();

            //Offer.Title = testTitle;
            //Offer.Description = testDescription;
            //Offer.Url = testUrl;
            //Offer.Category = testCategory;
            //Offer.CompanyId = testCompanyId;

            ////create (offercode)
            //var offerCode1 = new OfferCode();
            //offerCode1.Code = "A" + RandomDigits();
            //var offerCode2 = new OfferCode();
            //offerCode2.Code = "B" + RandomDigits();
            //var offerCode3 = new OfferCode();
            //offerCode3.Code = "C" + RandomDigits();
            //offerCode1.OfferId = Offer.Id;
            //offerCode2.OfferId = Offer.Id;
            //offerCode3.OfferId = Offer.Id;

            //OfferService offerService = new OfferService();

            //offerService.SaveOffer(Offer);
            //Assert.IsTrue(Offer.Id != 0);

            //offerCode1.OfferId = Offer.Id;
            //offerCode2.OfferId = Offer.Id;
            //offerCode3.OfferId = Offer.Id;

            //offerService.SaveOfferCode(offerCode1);
            //offerService.SaveOfferCode(offerCode2);
            //offerService.SaveOfferCode(offerCode3);
            //Assert.IsTrue(offerCode1.Id != 0);
            //Assert.IsTrue(offerCode2.Id != 0);
            //Assert.IsTrue(offerCode3.Id != 0);

            //var userId1 = "Jackie Bolton";

            //var code1 = offerService.ClaimNextCode(Offer.Id, userId1);
            //Assert.IsTrue(!String.IsNullOrEmpty(code1));
            ////Verify that the first code is claimed by Jackie
            //offerCode1 = offerService.GetOfferCode(offerCode1.Id);
            //Assert.IsTrue(offerCode1.ClaimingUser.Equals(userId1));

            //var userId2 = "Sandra Lollygagger";

            //var code2 = offerService.ClaimNextCode(Offer.Id, userId2);
            //Assert.IsTrue(!String.IsNullOrEmpty(code2));
            ////Verify that the second code is claimed by Sandra
            //offerCode2 = offerService.GetOfferCode(offerCode2.Id);
            //Assert.IsTrue(offerCode2.ClaimingUser.Equals(userId2));
            //Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode2.ClaimingUser));

            //var userId3 = "Kevin Spaceman";

            //var code3 = offerService.ClaimNextCode(Offer.Id, userId3);
            //Assert.IsTrue(!String.IsNullOrEmpty(code3));
            ////Verify that the third code is claimed by Kevin
            //offerCode3 = offerService.GetOfferCode(offerCode3.Id);
            //Assert.IsTrue(offerCode3.ClaimingUser.Equals(userId3));
            //Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode3.ClaimingUser));

            //var userId4 = "Richmond Nocode";

            //var code4 = offerService.ClaimNextCode(Offer.Id, userId4);
            ////This time verifying that code4 IS empty because we have no more codes in the offer.
            //Assert.IsTrue(String.IsNullOrEmpty(code4));

            //offerService.DeleteOfferCode(offerCode1.Id);
            //offerService.DeleteOfferCode(offerCode2.Id);
            //offerService.DeleteOfferCode(offerCode3.Id);

            //offerService.DeleteOffer(Offer.Id);
        }
Exemple #17
0
        public void ClaimOfferCodeCRUD()
        {
            var Offer           = new Offer();
            var testTitle       = "Necklaces";
            var testDescription = "80% off these shiny necklaces!";
            var testUrl         = "fakeurl.bamazon.necklaces/";
            var testCategory    = "Jewelry";



            var testCompanyId = RandomInteger();

            Offer.Title       = testTitle;
            Offer.Description = testDescription;
            Offer.Url         = testUrl;
            Offer.Category    = testCategory;
            Offer.CompanyId   = testCompanyId;

            //create (offercode)
            var offerCode1 = new OfferCode();

            offerCode1.Code = "ABCDEF" + RandomDigits();
            var offerCode2 = new OfferCode();

            offerCode2.Code = "GHIJKL" + RandomDigits();
            var offerCode3 = new OfferCode();

            offerCode3.Code = "MNOPQR" + RandomDigits();

            offerCode1.OfferId = Offer.Id;
            offerCode2.OfferId = Offer.Id;
            offerCode3.OfferId = Offer.Id;

            OfferService offerService = new OfferService();

            offerService.SaveOffer(Offer);
            Assert.IsTrue(Offer.Id != 0);

            offerCode1.OfferId = Offer.Id;
            offerCode2.OfferId = Offer.Id;
            offerCode3.OfferId = Offer.Id;

            offerService.SaveOfferCode(offerCode1);
            offerService.SaveOfferCode(offerCode2);
            offerService.SaveOfferCode(offerCode3);
            Assert.IsTrue(offerCode1.Id != 0);
            Assert.IsTrue(offerCode2.Id != 0);
            Assert.IsTrue(offerCode3.Id != 0);

            var userId1 = "Jackie Bolton";

            var code1 = offerService.ClaimNextCode(Offer.Id, userId1);

            Assert.IsTrue(!String.IsNullOrEmpty(code1));
            //Verify that the first code is claimed by Jackie
            offerCode1 = offerService.GetOfferCode(offerCode1.Id);
            Assert.IsTrue(offerCode1.ClaimingUser.Equals(userId1));

            var userId2 = "Sandra Lollygagger";

            var code2 = offerService.ClaimNextCode(Offer.Id, userId2);

            Assert.IsTrue(!String.IsNullOrEmpty(code2));
            //Verify that the second code is claimed by Sandra
            offerCode2 = offerService.GetOfferCode(offerCode2.Id);
            Assert.IsTrue(offerCode2.ClaimingUser.Equals(userId2));
            Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode2.ClaimingUser));

            var userId3 = "Kevin Spaceman";

            var code3 = offerService.ClaimNextCode(Offer.Id, userId3);

            Assert.IsTrue(!String.IsNullOrEmpty(code3));
            //Verify that the third code is claimed by Kevin
            offerCode3 = offerService.GetOfferCode(offerCode3.Id);
            Assert.IsTrue(offerCode3.ClaimingUser.Equals(userId3));
            Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode3.ClaimingUser));

            var userId4 = "Richmond Nocode";

            var code4 = offerService.ClaimNextCode(Offer.Id, userId4);

            //This time verifying that code4 IS empty because we have no more codes in the offer.
            Assert.IsTrue(String.IsNullOrEmpty(code4));

            offerService.DeleteOfferCode(offerCode1.Id);
            offerService.DeleteOfferCode(offerCode2.Id);
            offerService.DeleteOfferCode(offerCode3.Id);

            offerService.DeleteOffer(Offer.Id);
        }
Exemple #18
0
        public void OfferCodeCRUD()
        {
            //create (offer)
            var Offer           = new Offer();
            var testTitle       = "Sword Sale";
            var testDescription = "90% off these real dull swords!";
            var testUrl         = "fakeurl.bamazon.swords/";
            var testCategory    = "Weapons";
            var testCompanyId   = RandomInteger();

            Offer.Title       = testTitle;
            Offer.Description = testDescription;
            Offer.Url         = testUrl;
            Offer.Category    = testCategory;
            Offer.CompanyId   = testCompanyId;

            //create (offercode)
            var OfferCode = new OfferCode();
            var testCode  = "ABCDEF" + RandomDigits();

            OfferCode.OfferId = Offer.Id;
            OfferCode.Code    = testCode;

            var OfferService = new OfferService();

            OfferService.SaveOffer(Offer);
            Assert.IsTrue(Offer.Id != 0);

            OfferService.SaveOfferCode(OfferCode);
            Assert.IsTrue(OfferCode.Id != 0);

            // get it, verify it's there (offer)
            var OfferId = Offer.Id;
            var Offer2  = OfferService.GetOffer(OfferId);

            Assert.IsNotNull(Offer2);

            // get it, verify it's there (offercode)
            var OfferCodeId = OfferCode.Id;
            var OfferCode2  = OfferService.GetOfferCode(OfferCodeId);

            Assert.IsNotNull(OfferCode2);

            // verify property values (offer)
            Assert.AreEqual(Offer2.Title, testTitle);
            Assert.AreEqual(Offer2.Description, testDescription);
            Assert.AreEqual(Offer2.Url, testUrl);
            Assert.AreEqual(Offer2.Category, testCategory);
            Assert.AreEqual(Offer2.CompanyId, testCompanyId);

            //verify property values (offercode)
            Assert.AreEqual(OfferCode2.OfferId, OfferCode.OfferId);
            Assert.AreEqual(OfferCode2.Code, testCode);

            //update offercode
            var testCode2 = "XYZ123" + RandomDigits();

            OfferCode2.Code = testCode2;
            OfferService.SaveOfferCode(OfferCode2);

            // get it again, verify property values
            var OfferCode3 = OfferService.GetOfferCode(OfferCode2.Id);

            Assert.AreEqual(testCode2, OfferCode3.Code);

            //delete it
            OfferService.DeleteOfferCode(OfferCodeId);
            OfferCode3 = OfferService.GetOfferCode(OfferCodeId);
            Assert.IsNull(OfferCode3);
        }