Пример #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));
        }
Пример #3
0
        public bool Update(UserUpdateRequest entity)
        {
            User existed = _userRepo.GetById(entity.Id);

            if (existed == null)
            {
                return(false);
            }
            string   name    = entity.Name;
            string   img     = entity.Img;
            string   address = entity.Address;
            string   phone   = entity.Phone;
            DateTime dob     = entity.BirthDate;

            if (address != null)
            {
                if (!util.ValidRangeLengthInput(address, 1, 250))
                {
                    return(false);
                }
                existed.Address = address.Trim();
            }
            if (name != null)
            {
                if (!util.ValidRangeLengthInput(name, 1, 100))
                {
                    return(false);
                }
                existed.Name = name.Trim();
            }
            if (img != null)
            {
                if (!util.ValidRangeLengthInput(img, 1, 100))
                {
                    return(false);
                }
                existed.Img = img.Trim();
            }
            if (phone != null)
            {
                if (!util.ValidFixedLengthInput(phone, 10))
                {
                    return(false);
                }
                existed.Phone = phone.Trim();
            }
            if (dob.Millisecond > 0)
            {
                if (dob.AddDays(365 * 10).CompareTo(DateTime.Now) >= 0)
                {
                    return(false);
                }
                existed.BirthDate = dob;
            }
            existed.UpdatedDate = DateTime.Now;
            return(_userRepo.Update(existed));
        }