Exemplo n.º 1
0
        static public List <EBaseEntity> SearchByName(string companyID, string name)
        {
            using var context = new SMySQLContext();
            List <EBaseEntity> list = context.BaseUsers.Where(x => x.companyID == companyID && x.name.Contains(name)).ToList();

            return(list);
        }
Exemplo n.º 2
0
        static public async Task <string> Save(EBaseEntity eBaseEntity)
        {
            eBaseEntity.modificationDateUTC = DateTime.UtcNow;
            using var context = new SMySQLContext();
            if (string.IsNullOrEmpty(eBaseEntity.id))
            {
                eBaseEntity.id = Guid.NewGuid().ToString();

                eBaseEntity.creationDateUTC = DateTime.UtcNow;
                var e = await context.BaseUsers.AddAsync(eBaseEntity);

                await context.SaveChangesAsync();

                eBaseEntity.id = e.Entity.id;
            }
            else
            {
                var e = context.BaseUsers.Update(eBaseEntity);
                await context.SaveChangesAsync();

                eBaseEntity.id = e.Entity.id;
            }
            SBaseAddresses.SaveClientAddresses(eBaseEntity.id, eBaseEntity.addressList);
            return(eBaseEntity.id);
        }
        static public List <EDeliveryProduct> GetAll(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "name asc")
        {
            using var context = new SMySQLContext();
            List <EDeliveryProduct> list = null;

            if (listCount == -1)
            {
                list = context.DeliveryProducts.Where(x => x.companyID == companyID).OrderBy(orderBy).ToList();
            }
            else
            {
                list = context.DeliveryProducts.Where(x => x.companyID == companyID).OrderBy(orderBy).Skip(pageNumber * listCount).Take(listCount).ToList();
            }
            foreach (EDeliveryProduct eProduct in list)
            {
                if (!string.IsNullOrEmpty(eProduct.option1ParentGroupID))
                {
                    eProduct.option1ParentGroupName = SDeliveryProductsOptions.GetInternalNameIfAvailable(eProduct.option1ParentGroupID);
                }
                if (!string.IsNullOrEmpty(eProduct.option2ParentGroupID))
                {
                    eProduct.option2ParentGroupName = SDeliveryProductsOptions.GetInternalNameIfAvailable(eProduct.option2ParentGroupID);
                }
                if (!string.IsNullOrEmpty(eProduct.addon1ParentGroupID))
                {
                    eProduct.addon1ParentGroupName = SDeliveryProductsAddons.GetByID(eProduct.addon1ParentGroupID).name;
                }
            }
            //EList eList = new EList {items = list.Cast<object>().ToList(), totalListCount = context.DeliveryProducts.Count(x=>x.companyID==companyID)};
            return(list);
        }
        static public async Task <EDeliveryProduct> GetByID(string id)
        {
            using var context = new SMySQLContext();
            EDeliveryProduct eDeliveryProduct = await context.DeliveryProducts.SingleOrDefaultAsync(x => x.id == id);

            if (!string.IsNullOrEmpty(eDeliveryProduct.option1ParentGroupID))
            {
                eDeliveryProduct.option1ParentGroupName = SDeliveryProductsOptions.GetByID(eDeliveryProduct.option1ParentGroupID).name;
            }
            if (!string.IsNullOrEmpty(eDeliveryProduct.option2ParentGroupID))
            {
                eDeliveryProduct.option2ParentGroupName = SDeliveryProductsOptions.GetByID(eDeliveryProduct.option2ParentGroupID).name;
            }
            if (!string.IsNullOrEmpty(eDeliveryProduct.addon1ParentGroupID))
            {
                eDeliveryProduct.addon1ParentGroupName = SDeliveryProductsAddons.GetByID(eDeliveryProduct.addon1ParentGroupID).name;
            }
            if (!string.IsNullOrEmpty(eDeliveryProduct.addon2ParentGroupID))
            {
                eDeliveryProduct.addon2ParentGroupName = SDeliveryProductsAddons.GetByID(eDeliveryProduct.addon2ParentGroupID).name;
            }
            if (!string.IsNullOrEmpty(eDeliveryProduct.addon3ParentGroupID))
            {
                eDeliveryProduct.addon3ParentGroupName = SDeliveryProductsAddons.GetByID(eDeliveryProduct.addon3ParentGroupID).name;
            }
            return(eDeliveryProduct);
        }
Exemplo n.º 5
0
        static public async Task <EUserAuth> CreateUserFromMobile(EBaseEntity eNewUser)
        {
            try {
                EUserAuth eUserAuth = new EUserAuth {
                };
                using (var context = new SMySQLContext()) {
                    if (context.BaseUsers.Any(x => x.email == eNewUser.email))
                    {
                        eUserAuth.respCreateUser = (int)RespCreateUser.EmailExists;
                        return(eUserAuth);
                    }
                    eNewUser.id = Guid.NewGuid().ToString();
                    eNewUser.creationDateUTC     = DateTime.UtcNow;
                    eNewUser.modificationDateUTC = DateTime.UtcNow;
                    eNewUser.lastAccessUTC       = DateTime.UtcNow;
                    eNewUser.status = (int)UserStatus.Enabled;
                    EBaseEntity result = context.BaseUsers.AddAsync(eNewUser).Result.Entity;
                    await context.SaveChangesAsync();

                    eUserAuth.id             = result.id;
                    eUserAuth.cpf            = result.cpf;
                    eUserAuth.name           = result.name;
                    eUserAuth.token          = STokens.GenerateToken(eNewUser.email);
                    eUserAuth.authenticated  = true;
                    eUserAuth.respCreateUser = (int)RespCreateUser.Ok;
                }
                return(eUserAuth);
            } catch (Exception e) {
                SLogger.LogError(e);
            }
            return(null);
        }
 static public ECompanyBillToPay GetByID(string id)
 {
     using (var context = new SMySQLContext()) {
         ECompanyBillToPay eBillToPay = context.CompanyBillsToPay.SingleOrDefault(x => x.id == id);
         return(eBillToPay);
     }
 }
 static public ECompanyBillToReceive GetByID(string id)
 {
     using (var context = new SMySQLContext()) {
         ECompanyBillToReceive eBillToReceive = context.CompanyBillsToReceive.SingleOrDefault(x => x.id == id);
         return(eBillToReceive);
     }
 }
Exemplo n.º 8
0
        static public bool SaveProfile(EBaseEntity eBaseEntity)
        {
            using var context = new SMySQLContext();
            EBaseEntity oldEntity = context.BaseUsers.SingleOrDefault(x => x.id == eBaseEntity.id);

            oldEntity.email    = eBaseEntity.email;
            oldEntity.password = eBaseEntity.password;
            context.BaseUsers.Update(oldEntity);
            return(SBaseAddresses.SaveClientAddresses(eBaseEntity.id, eBaseEntity.addressList));
        }
Exemplo n.º 9
0
        static public EBaseEntity GetByID(string id, bool includeAddresses = false)
        {
            using var context = new SMySQLContext();
            EBaseEntity eBaseEntity = context.BaseUsers.SingleOrDefault(x => x.id == id);

            eBaseEntity.password = "";
            if (includeAddresses)
            {
                eBaseEntity.addressList = SBaseAddresses.GetClientAddresses(id);
            }
            return(eBaseEntity);
        }
Exemplo n.º 10
0
        static public async Task <bool> Remove(string id)
        {
            using (var context = new SMySQLContext()) {
                EBaseEntity eBaseEntity = context.BaseUsers.SingleOrDefault(x => x.id == id);
                if (eBaseEntity == null)
                {
                    return(false);
                }
                context.Remove(eBaseEntity);
                await context.SaveChangesAsync();

                return(true);
            }
        }
        //=====================================================GETS ABOVE=====================================================

        #region Remove
        static public async Task <bool> Remove(string id)
        {
            using var context = new SMySQLContext();
            EDeliveryProduct eProduct = context.DeliveryProducts.SingleOrDefault(x => x.id == id);

            if (eProduct == null)
            {
                return(false);
            }
            context.Remove(eProduct);
            await context.SaveChangesAsync();

            return(true);
        }
        static public async Task <bool> Remove(string id)
        {
            using (var context = new SMySQLContext()) {
                ECompanyBillToPay eBillToPay = context.CompanyBillsToPay.SingleOrDefault(x => x.id == id);
                if (eBillToPay == null)
                {
                    return(false);
                }
                context.Remove(eBillToPay);
                await context.SaveChangesAsync();

                return(true);
            }
        }
Exemplo n.º 13
0
        static public List <EBaseEntity> GetAll(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "name asc")
        {
            using var context = new SMySQLContext();
            List <EBaseEntity> list = null;

            if (listCount == -1)
            {
                list = context.BaseUsers.Where(x => x.companyID == companyID).OrderBy(orderBy).ToList();
            }
            else
            {
                list = context.BaseUsers.Where(x => x.companyID == companyID).Skip(pageNumber * listCount).Take(listCount).OrderBy(orderBy).ToList();
            }
            return(list);
        }
Exemplo n.º 14
0
        static public EUserAuth Authenticate(string email, string password)
        {
            using var context = new SMySQLContext();
            EBaseEntity eBaseEntity = context.BaseUsers.SingleOrDefault(x => x.email == email && x.password == password);

            if (eBaseEntity == null)
            {
                return new EUserAuth {
                           authenticated = false
                }
            }
            ;
            EUserAuth eUserAuth = GetUserAuthFromBaseEntity(eBaseEntity);

            eUserAuth.authenticated = true;
            return(eUserAuth);
        }
        static public async Task <string> Save(EDeliveryProduct eProduct)
        {
            using var context            = new SMySQLContext();
            eProduct.modificationDateUTC = DateTime.UtcNow;
            if (string.IsNullOrEmpty(eProduct.option1ParentGroupID))
            {
                eProduct.option1ParentGroupID = null;
            }
            if (string.IsNullOrEmpty(eProduct.option2ParentGroupID))
            {
                eProduct.option2ParentGroupID = null;
            }
            if (string.IsNullOrEmpty(eProduct.option3ParentGroupID))
            {
                eProduct.option3ParentGroupID = null;
            }
            if (string.IsNullOrEmpty(eProduct.addon1ParentGroupID))
            {
                eProduct.addon1ParentGroupID = null;
            }
            if (string.IsNullOrEmpty(eProduct.addon2ParentGroupID))
            {
                eProduct.addon2ParentGroupID = null;
            }
            if (string.IsNullOrEmpty(eProduct.addon3ParentGroupID))
            {
                eProduct.addon3ParentGroupID = null;
            }
            if (string.IsNullOrEmpty(eProduct.id))
            {
                eProduct.id = Guid.NewGuid().ToString();
                eProduct.creationDateUTC = DateTime.UtcNow;
                var e = await context.DeliveryProducts.AddAsync(eProduct);

                await context.SaveChangesAsync();

                return(e.Entity.id);
            }
            else
            {
                var e = context.DeliveryProducts.Update(eProduct);
                await context.SaveChangesAsync();

                return(e.Entity.id);
            }
        }
        //=====================================================GETS ABOVE=====================================================

        #region Save
        static public async Task <string> Save(ECompanyBillToPay eBillToPay)
        {
            eBillToPay.modificationDateUTC = DateTime.UtcNow;
            using (var context = new SMySQLContext()) {
                if (string.IsNullOrEmpty(eBillToPay.id))
                {
                    eBillToPay.id = Guid.NewGuid().ToString();
                    eBillToPay.creationDateUTC = DateTime.UtcNow;
                    var e = await context.CompanyBillsToPay.AddAsync(eBillToPay);

                    await context.SaveChangesAsync();

                    return(e.Entity.id);
                }
                else
                {
                    var e = context.CompanyBillsToPay.Update(eBillToPay);
                    await context.SaveChangesAsync();

                    return(e.Entity.id);
                }
            }
        }
 static public List <ECompanyBillToPay> GetAll(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "id desc")
 {
     using (var context = new SMySQLContext()) {
         List <ECompanyBillToPay> list = null;
         if (listCount == -1)
         {
             list = context.CompanyBillsToPay.Where(x => x.companyID == companyID).OrderBy(orderBy).ToList();
         }
         else
         {
             list = context.CompanyBillsToPay.Where(x => x.companyID == companyID).OrderBy(orderBy).Skip(pageNumber * listCount).Take(listCount).ToList();
         }
         foreach (ECompanyBillToPay eBillToPay in list)
         {
             if (string.IsNullOrEmpty(eBillToPay.toEntityID))
             {
                 continue;
             }
             eBillToPay.entityName = SBaseEntities.GetByID(eBillToPay.toEntityID, false).name;
         }
         return(list);
     }
 }
 static public Int64 GetCount(string companyID)
 {
     using var context = new SMySQLContext();
     return(context.CompanyBillsToPay.Count(x => x.companyID == companyID));
 }
 static public Int64 GetCount(string companyID)
 {
     using var context = new SMySQLContext();
     return(context.DeliveryProducts.Count(x => x.companyID == companyID));
 }
Exemplo n.º 20
0
 static public List <EBank> GetAll()
 {
     using var context = new SMySQLContext();
     return(context.Banks.OrderBy(x => x.name).ToList());
 }