Esempio n. 1
0
        public ApiResult <Customer> Update(int id,
                                           CreateCustomerOptions options)
        {
            ApiResult <Customer> res = GetCustomerById(id);

            if (!res.Success)
            {
                return(res);
            }

            if (options == null)
            {
                return(ApiResult <Customer> .CreateUnsuccessful
                           (StatusCode.BadRequest, "null options"));
            }
            Customer c = res.Data;

            if (!string.IsNullOrWhiteSpace(options.Email) &&
                options.Email.Contains("@"))
            {
                c.Email = options.Email;
            }

            context.SaveChanges();

            return(ApiResult <Customer> .CreateSuccessful(c));
        }
Esempio n. 2
0
        public ApiResult <IQueryable <Customer> > Search(
            SearchCustomerOptions options)
        {
            if (options == null)
            {
                return(ApiResult <IQueryable <Customer> > .CreateUnsuccessful
                           (StatusCode.BadRequest, "null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Email) &&
                (options.Id == null || options.Id == 0) &&
                string.IsNullOrWhiteSpace(options.VatNumber) &&
                string.IsNullOrWhiteSpace(options.FirstName)
                )
            {
                return(ApiResult <IQueryable <Customer> > .CreateUnsuccessful
                           (StatusCode.BadRequest, "null options"));
            }

            var query = context
                        .Set <Customer>()
                        .AsQueryable();

            if (options.Id != null && options.Id != 0)
            {
                query = query.Where(
                    c => c.Id == options.Id);
            }

            if (options.VatNumber != null)
            {
                query = query.Where(
                    c => c.VatNumber == options.VatNumber);
            }

            if (options.Email != null)
            {
                query = query.Where(
                    c => c.Email.Equals(options.Email));
            }

            if (!string.IsNullOrWhiteSpace(options.FirstName))
            {
                query = query
                        .Where(c => c.FirstName.Contains(options.FirstName));
            }

            return(ApiResult <IQueryable <Customer> > .CreateSuccessful(query));
        }
Esempio n. 3
0
        public ApiResult <IQueryable <Order> > SearchOrder(
            SearchOrderOptions options)
        {
            if (options == null)
            {
                return(ApiResult <IQueryable <Order> > .CreateUnsuccessful(
                           StatusCode.BadRequest, "Null order"));
            }

            if (options.OrderId == null &&
                options.CustomerId == null &&
                options.VatNumber == null)
            {
                return(new ApiResult <IQueryable <Order> >(
                           StatusCode.BadRequest, "Null order"));
            }

            var query = context_
                        .Set <Order>()
                        .AsQueryable();

            if (options.OrderId != null)
            {//check guid
                query = query.Where(o => o.Id.Equals(options.OrderId));
            }

            if (options.CustomerId != null)
            {
                query = query.Where(o => o.CustomerId.Equals(options.CustomerId));
            }

            if (options.VatNumber != null)
            {
                query = query.Where(o => o.Customer.VatNumber.Equals(options.VatNumber));
            }

            return(ApiResult <IQueryable <Order> > .CreateUnsuccessful(
                       StatusCode.BadRequest, "Null order"));
        }