Example #1
0
        public Role CreateRole(Role roleToAdd)
        {
            if (roleToAdd == null)
            {
                return(null);
            }

            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var r = context.Roles.Add(new Role()
                {
                    Label       = roleToAdd.Label,
                    Users       = new List <User>(),
                    RoleModules = new List <RoleModule>()
                });
                context.SaveChanges();

                foreach (RoleModule rm in roleToAdd.RoleModules)
                {
                    context.RoleModules.Add(new RoleModule()
                    {
                        Role_id   = r.Id,
                        Module_id = rm.Module_id
                    });
                }

                context.SaveChanges();
                return(r);
            }
        }
Example #2
0
        private void CalculateTTC()
        {
            var htRef   = 0.00;
            var context = new SUPERPEntities();
            var lstLine = context.BILL_LineBillQuotation.Where(l => l.BillQuotation_Id == BillQuotation_Id);

            foreach (var line in lstLine)
            {
                var tvaRate = (line.BILL_Product.BILL_Vat.Rate == null) ? 0.00 : Convert.ToDouble(line.BILL_Product.BILL_Vat.Rate);

                double priceProductTTC = (tvaRate * line.BILL_Product.Price) + line.BILL_Product.Price;
                htRef     += line.BILL_Product.Price * line.Quantite;
                AmountTTC += priceProductTTC * line.Quantite;
            }

            /* Check if amountHT is valid */
            if (htRef != AmountDF)
            {
                var b = context.BILL_BillQuotation.Find(BillQuotation_Id);
                b.AmountDF = htRef;
                context.SaveChanges();
            }

            /* Check if VAT is affected */
            if (!Vat)
            {
                AmountTTC = AmountDF;
            }
        }
Example #3
0
        public User EditUser(User userToEdit)
        {
            if (userToEdit == null)
            {
                return(null);
            }

            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var u = context.Users.Find(userToEdit.Id);
                if (u == null)
                {
                    return(null);
                }

                u.Address   = userToEdit.Address;
                u.Email     = userToEdit.Email;
                u.Firstname = userToEdit.Firstname;
                u.Lastname  = userToEdit.Lastname;

                if (userToEdit.Role != null)
                {
                    u.Role    = context.Roles.Find(userToEdit.Role.Id);
                    u.Role_id = u.Role.Id;
                }

                u.Zip_code = userToEdit.Zip_code;
                u.City     = userToEdit.City;
                context.SaveChanges();
                return(u);
            }
        }
Example #4
0
 public COMPTA_AccountingEntries CreateAccountingEntry(COMPTA_AccountingEntries accountingEntryToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var accountingEntry = context.COMPTA_AccountingEntries.Add(accountingEntryToAdd);
         context.SaveChanges();
         return(accountingEntry);
     }
 }
Example #5
0
 public COMPTA_BankJournalLine CreateBankJournalLine(COMPTA_BankJournalLine bankJournalLineToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var bankJournalLine = context.COMPTA_BankJournalLine.Add(bankJournalLineToAdd);
         context.SaveChanges();
         return(bankJournalLine);
     }
 }
Example #6
0
 public COMPTA_Bank CreateBank(COMPTA_Bank bankToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var bank = context.COMPTA_Bank.Add(bankToAdd);
         context.SaveChanges();
         return(bank);
     }
 }
Example #7
0
 public COMPTA_BankAccount CreateBankAccount(COMPTA_BankAccount bankAccountToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var bankAccount = context.COMPTA_BankAccount.Add(bankAccountToAdd);
         context.SaveChanges();
         return(bankAccount);
     }
 }
Example #8
0
 public COMPTA_Currency CreateCurrency(COMPTA_Currency currencyToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var currency = context.COMPTA_Currency.Add(currencyToAdd);
         context.SaveChanges();
         return(currency);
     }
 }
Example #9
0
 public COMPTA_ExchangeRate CreateExchangeRate(COMPTA_ExchangeRate exchangeRateToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var exchangeRate = context.COMPTA_ExchangeRate.Add(exchangeRateToAdd);
         context.SaveChanges();
         return(exchangeRate);
     }
 }
Example #10
0
 public COMPTA_ChartOfAccounts CreateAccountingAccount(COMPTA_ChartOfAccounts accountingAccountToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var accountingAccount = context.COMPTA_ChartOfAccounts.Add(accountingAccountToAdd);
         context.SaveChanges();
         return(accountingAccount);
     }
 }
Example #11
0
 public COMPTA_ClassOfAccounts CreateAccountingClass(COMPTA_ClassOfAccounts accountingClassToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var accountingClass = context.COMPTA_ClassOfAccounts.Add(accountingClassToAdd);
         context.SaveChanges();
         return(accountingClass);
     }
 }
Example #12
0
 public COMPTA_SupplierJournalLine CreateSupplierJournalLine(COMPTA_SupplierJournalLine supplierJournalLineToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var supplierJournalLine = context.COMPTA_SupplierJournalLine.Add(supplierJournalLineToAdd);
         context.SaveChanges();
         return(supplierJournalLine);
     }
 }
Example #13
0
 public COMPTA_CustomerJournalLine CreateCustomerJournalLine(COMPTA_CustomerJournalLine customerJournalLineToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var customerJournalLine = context.COMPTA_CustomerJournalLine.Add(customerJournalLineToAdd);
         context.SaveChanges();
         return(customerJournalLine);
     }
 }
Example #14
0
 public BILL_BillQuotation CreateBillQutotation(BILL_BillQuotation billQuotationToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var b = context.BILL_BillQuotation.Add(billQuotationToAdd);
         context.SaveChanges();
         return(b);
     }
 }
Example #15
0
 public BILL_Product CreateBillProduct(BILL_Product billProductToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var p = context.BILL_Product.Add(billProductToAdd);
         context.SaveChanges();
         return(p);
     }
 }
Example #16
0
 public BILL_Product EditBillProduct(BILL_Product billProductToEdit)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var p = context.BILL_Product.Find(billProductToEdit.Product_Id);
         p = billProductToEdit;
         context.SaveChanges();
         return(p);
     }
 }
Example #17
0
 public bool DeleteCompany_Contact(int id)
 {
     using (SUPERPEntities sup = new SUPERPEntities(false))
     {
         Company_Contact contact = sup.Company_Contact.Where(p => p.id == id).FirstOrDefault();
         sup.Entry(contact).State = System.Data.Entity.EntityState.Deleted;
         sup.SaveChanges();
     }
     return(true);
 }
Example #18
0
        public int CreateCompany_Contact(Company_Contact contact)
        {
            using (SUPERPEntities sup = new SUPERPEntities(false))
            {
                sup.Company_Contact.Add(contact);
                sup.SaveChanges();

                Company_Contact cont = sup.Company_Contact.OrderByDescending(p => p.id).First();
                return((int)cont.id);
            }
        }
Example #19
0
        public Role EditRole(Role roleToEdit)
        {
            if (roleToEdit == null)
            {
                return(null);
            }

            var listToAdd = new List <RoleModule>();

            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var r = context.Roles.Include("RoleModules").Include("RoleModules.Module").Include("RoleModules.Role").FirstOrDefault(x => x.Id == roleToEdit.Id);
                if (r == null)
                {
                    return(null);
                }

                context.RoleModules.RemoveRange(r.RoleModules);
                context.SaveChanges();
                r.RoleModules.Clear();
                foreach (var rm in roleToEdit.RoleModules)
                {
                    RoleModule rrm = null;
                    if ((rrm = r.RoleModules.FirstOrDefault(x => x.Id == rm.Id)) == null)
                    {
                        listToAdd.Add(new RoleModule()
                        {
                            Module_id = rm.Module_id,
                            Role_id   = rm.Role_id
                        });
                    }
                }

                context.RoleModules.AddRange(listToAdd);

                r.Label = roleToEdit.Label;
                context.SaveChanges();
                return(r);
            }
        }
Example #20
0
 public bool EditCompany_Contact(Company_Contact contact)
 {
     using (SUPERPEntities sup = new SUPERPEntities(false))
     {
         Company_Contact contactBdd = sup.Company_Contact.Where(p => p.id == contact.id).FirstOrDefault();
         if (contactBdd != null)
         {
             sup.Entry(contactBdd).CurrentValues.SetValues(contact);
             sup.SaveChanges();
         }
     }
     return(true);
 }
Example #21
0
        public void SetNumFacture()
        {
            var result = new BILL_BillQuotation();

            try
            {
                using (SUPERPEntities context = new SUPERPEntities(false))
                {
                    var results = context.BILL_BillQuotation.OrderByDescending(b => b.BillQuotation_Id);
                    if (results != null)
                    {
                        result = results.First();
                        if (result != null && result.NBill.Equals("1"))
                        {
                            var numStr = "000000001";

                            var num           = Convert.ToInt32(numStr);
                            var billQuotation = context.BILL_BillQuotation.OrderByDescending(b => b.NBill).Where(b => !b.NBill.Equals("1"));
                            if (billQuotation != null && billQuotation.Count() > 0)
                            {
                                var nbill = billQuotation.First().NBill;
                                if (nbill != null)
                                {
                                    var intNum = Convert.ToInt32(nbill) + 1;
                                    numStr = intNum.ToString();
                                }
                            }

                            while (numStr.Length < 9)
                            {
                                numStr = "0" + numStr;
                            }

                            //Set NbBill
                            result.NBill = numStr;
                        }
                        else if (result != null && result.NBill.Equals("0"))
                        {
                            result.NBill = null;
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public List <BILL_LineBillQuotation> CreateLineBillQuotation(List <BILL_LineBillQuotation> billLineToAdd)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var listLine = new List <BILL_LineBillQuotation>();
         foreach (var line in billLineToAdd)
         {
             var s = context.BILL_LineBillQuotation.Add(line);
             listLine.Add(line);
         }
         context.SaveChanges();
         return(listLine);
     }
 }
Example #23
0
        public User CreateUser(User userToAdd)
        {
            if (userToAdd == null)
            {
                return(null);
            }

            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                userToAdd.Passwordhash = Encrypt.hashSHA256(userToAdd.Passwordhash);
                var u = context.Users.Add(userToAdd);
                context.SaveChanges();
                return(u);
            }
        }
 public List <BILL_LineBillQuotation> EditLineBillQuotation(List <BILL_LineBillQuotation> LineBillQuotationToEdit)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var listLine = new List <BILL_LineBillQuotation>();
         foreach (var line in LineBillQuotationToEdit)
         {
             var l = context.BILL_LineBillQuotation.Find(line.LineBillQuotation_Id);
             l = line;
             listLine.Add(l);
         }
         context.SaveChanges();
         return(listLine);
     }
 }
Example #25
0
        public COMPTA_BankJournalLine EditBankJournalLine(COMPTA_BankJournalLine bankJournalLineToEdit)
        {
            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var bankJournalLine = context.COMPTA_BankJournalLine.Find(bankJournalLineToEdit.id);

                if (bankJournalLine == null)
                {
                    return(null);
                }

                bankJournalLine = bankJournalLineToEdit;
                context.SaveChanges();
                return(bankJournalLine);
            }
        }
Example #26
0
        public COMPTA_BankAccount EditBankAccount(COMPTA_BankAccount bankAccountToEdit)
        {
            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var bankAccount = context.COMPTA_BankAccount.Find(bankAccountToEdit.id);

                if (bankAccount == null)
                {
                    return(null);
                }

                bankAccount = bankAccountToEdit;
                context.SaveChanges();
                return(bankAccount);
            }
        }
Example #27
0
        public COMPTA_AccountingEntries EditAccountingEntry(COMPTA_AccountingEntries accountingEntryToEdit)
        {
            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var accountingEntry = context.COMPTA_AccountingEntries.Find(accountingEntryToEdit.id);

                if (accountingEntry == null)
                {
                    return(null);
                }

                accountingEntry = accountingEntryToEdit;
                context.SaveChanges();
                return(accountingEntry);
            }
        }
Example #28
0
        public COMPTA_CustomerJournalLine EditCustomerJournalLine(COMPTA_CustomerJournalLine customerJournalLineToEdit)
        {
            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var customerJournalLine = context.COMPTA_CustomerJournalLine.Find(customerJournalLineToEdit.id);

                if (customerJournalLine == null)
                {
                    return(null);
                }

                customerJournalLine = customerJournalLineToEdit;
                context.SaveChanges();
                return(customerJournalLine);
            }
        }
Example #29
0
        public COMPTA_SupplierJournalLine EditSupplierJournalLine(COMPTA_SupplierJournalLine supplierJournalLineToEdit)
        {
            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var supplierJournalLine = context.COMPTA_SupplierJournalLine.Find(supplierJournalLineToEdit.id);

                if (supplierJournalLine == null)
                {
                    return(null);
                }

                supplierJournalLine = supplierJournalLineToEdit;
                context.SaveChanges();
                return(supplierJournalLine);
            }
        }
Example #30
0
 public BILL_BillQuotation EditBillQuotation(BILL_BillQuotation billQuotationToEdit)
 {
     using (SUPERPEntities context = new SUPERPEntities(false))
     {
         var b = context.BILL_BillQuotation.Find(billQuotationToEdit.BillQuotation_Id);
         if (b != null)
         {
             b.AmountDF       = billQuotationToEdit.AmountDF;
             b.Company_Id     = billQuotationToEdit.Company_Id;
             b.Transmitter_Id = billQuotationToEdit.Transmitter_Id;
             b.Vat            = billQuotationToEdit.Vat;
             context.SaveChanges();
         }
         return(b);
     }
 }