Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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 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);
            }
        }
        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);
            }
        }
        //=====================================================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);
                }
            }
        }
Ejemplo n.º 6
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);
        }