示例#1
0
        public bool Create(StoreCreateRequest entity)
        {
            int    brandId = entity.BrandId;
            string name    = entity.Name;
            string address = entity.Address;
            string phone   = entity.Phone;

            if (!util.ValidRangeLengthInput(name, 1, 100) ||
                !util.ValidRangeLengthInput(address, 1, 250) ||
                !util.ValidFixedLengthInput(phone, 10))
            {
                return(false);
            }

            Store existed = _repo.GetAll().FirstOrDefault(e => e.Name.ToLower().Equals(name.ToLower()));

            if (existed != null)
            {
                return(false);
            }

            Store newEntity = new Store();

            newEntity.Name    = name.Trim();
            newEntity.BrandId = brandId;
            newEntity.Phone   = phone.Trim();
            newEntity.Address = address.Trim();

            return(_repo.Create(newEntity));
        }
示例#2
0
        public bool Create(BrandCreateRequest entity)
        {
            string name    = entity.Name;
            string address = entity.Address;
            string phone   = entity.Phone;
            string website = entity.Website;

            if (!util.ValidRangeLengthInput(name, 1, 100) ||
                !util.ValidRangeLengthInput(address, 1, 250) ||
                !util.ValidRangeLengthInput(website, 1, 100) ||
                !util.ValidFixedLengthInput(phone, 10))
            {
                return(false);
            }

            Brand exsited = _repo.GetAll().FirstOrDefault(e => e.Name.ToLower().Equals(name.Trim().ToLower()));

            if (exsited != null)
            {
                return(false);
            }

            Brand newEntity = new Brand();

            newEntity.Name    = name.Trim();
            newEntity.Address = address.Trim();
            newEntity.Phone   = phone.Trim();
            newEntity.Website = website.Trim();

            return(_repo.Create(newEntity));
        }
        public bool Create(PromotionCreateRequest entity)
        {
            string   description = entity.Description;
            DateTime beginDate   = entity.BeginDate;
            DateTime expiredDate = entity.ExpiredDate;

            if (!util.ValidRangeLengthInput(description, 1, 250) ||
                beginDate == null ||
                expiredDate == null ||
                beginDate.CompareTo(expiredDate) >= 0)
            {
                return(false);
            }

            Promotion existed = _proRepo.GetAll()
                                .FirstOrDefault(e => e.Description.Trim().ToLower().Equals(description.Trim().ToLower()));

            if (existed != null)
            {
                return(false);
            }
            Promotion newEntity = new Promotion();

            newEntity.Description = description.Trim();
            newEntity.BeginDate   = beginDate;
            newEntity.BrandId     = entity.BrandId;

            return(_proRepo.Create(newEntity));
        }
示例#4
0
        public bool Create(VoucherCreateRequest entity)
        {
            string   description       = entity.Description;
            int      quantity          = entity.Quantity;
            int      available         = quantity;
            string   code              = entity.Code;
            DateTime beginDate         = entity.BeginDate;
            DateTime expiredDate       = entity.ExpiredDate;
            int      maxDiscount       = entity.MaxDiscountAmount;
            int      minRequiredAmount = entity.MinRequiredAmount;
            int      percentDiscount   = entity.PercentDiscount;
            int      proId             = entity.PromotionId;

            if (!util.ValidRangeLengthInput(description, 1, 250) ||
                !util.ValidRangeLengthInput(code, 1, 20) ||
                beginDate.CompareTo(expiredDate) == 1 ||
                quantity < 0 ||
                percentDiscount <= 0 || maxDiscount <= 0 || minRequiredAmount <= 0
                )
            {
                return(false);
            }

            Voucher existed = _vouRepo.GetAll().FirstOrDefault(e => e.Code.Trim().ToLower().Equals(code.Trim().ToLower()));

            if (existed != null)
            {
                return(false);
            }
            Voucher newEntity = new Voucher();

            newEntity.Description       = description;
            newEntity.Quantity          = quantity;
            newEntity.Available         = available;
            newEntity.Code              = code;
            newEntity.BeginDate         = beginDate;
            newEntity.ExpiredDate       = expiredDate;
            newEntity.MinRequiredAmount = minRequiredAmount;
            newEntity.MaxDiscountAmount = maxDiscount;
            newEntity.PercentDiscount   = percentDiscount;
            newEntity.PromotionId       = proId;
            return(_vouRepo.Create(newEntity));
        }
示例#5
0
        public bool Create(UserCreateRequest entity)
        {
            string   gmail         = entity.Gmail;
            string   gmailToken    = entity.GmailToken;
            string   facebook      = entity.Facebook;
            string   facebookToken = entity.FacebookToken;
            string   name          = entity.Name;
            string   img           = entity.Img;
            string   address       = entity.Address;
            string   phone         = entity.Phone;
            DateTime dob           = entity.BirthDate;

            if (gmail == null && facebook == null)
            {
                return(false);
            }

            User newEntity = new User();

            newEntity.Name          = name;
            newEntity.Address       = address;
            newEntity.BirthDate     = dob;
            newEntity.CreatedDate   = DateTime.Now;
            newEntity.Img           = img;
            newEntity.Phone         = phone;
            newEntity.Gmail         = gmail;
            newEntity.GmailToken    = gmailToken;
            newEntity.Facebook      = facebook;
            newEntity.FacebookToken = facebookToken;

            //facebook
            if (util.ValidRangeLengthInput(facebook, 1, 100) && util.ValidRangeLengthInput(facebookToken, 1, 500))
            {
                if (!_userRepo.ExistedFacebook(facebook))
                {
                    User existed = _userRepo.GetAll().FirstOrDefault(e => e.Facebook.Equals(facebook) || e.FacebookToken.Equals(facebookToken));
                    if (existed == null)
                    {
                        return(_userRepo.Create(newEntity));
                    }
                }
            }

            //gmail
            if (util.ValidRangeLengthInput(gmail, 1, 100) && util.ValidRangeLengthInput(gmailToken, 1, 500))
            {
                if (!_userRepo.ExistedGmail(gmail))
                {
                    User existed = _userRepo.GetAll().FirstOrDefault(e => e.Gmail.Equals(gmail) || e.GmailToken.Equals(gmailToken));
                    if (existed == null)
                    {
                        return(_userRepo.Create(newEntity));
                    }
                }
            }
            return(false);
        }