Beispiel #1
0
 public bool ChangeKwotaKatWyd(decimal kwota, int idKatWyd, string userName)
 {
     using (var context = new CheaperEntities())
     {
         try
         {
             ExpenseCategories katWyd = (from c in context.ExpenseCategories where c.UserID == userName && c.Id == idKatWyd select c).First();
             //if (katWyd == null)
             //    throw new NullReferenceException("Próba zmiany kwoty kategorii wydatku nie należącej do użytkownika");
             katWyd.Amount = kwota;
             if (context.SaveChanges() == 1)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception ex)
         {
             throw new Exception("Próba zmiany kwoty kategorii wydatku nie należącej do użytkownika", ex);
         }
     }
 }
Beispiel #2
0
    public bool LogEvent(string methodName, Exception exception, string userName)
    {
        using (var context = new CheaperEntities())
        {
            var nowyEvent = new Events();
            nowyEvent.MethodName = methodName;
            nowyEvent.ExMessage  = exception.Message;
            if (exception.InnerException != null)
            {
                nowyEvent.InnerExMessage = exception.InnerException.Message;
            }
            nowyEvent.OccurenceDate = DateTime.Now;
            if (!string.IsNullOrEmpty(userName))
            {
                nowyEvent.UserName = userName;
            }
            else
            {
                nowyEvent.UserName = "******";
            }

            context.Events.AddObject(nowyEvent);

            if (context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Beispiel #3
0
    public bool RegisterNewUser(string login, string password, string email, DateTime birthDate, bool statsEnabled)
    {
        using (var context = new CheaperEntities())
        {
            var nowyUser = new Users();
            nowyUser.UserName     = login;
            nowyUser.Passwd       = GetMD5Hash(password);
            nowyUser.Email        = email;
            nowyUser.BirthDate    = birthDate;
            nowyUser.RegisterDate = DateTime.Now;

            var nowyUserAddInfo = new AdditionalUserInfo();
            nowyUserAddInfo.UserID        = login;
            nowyUserAddInfo.ShowEmail     = false;
            nowyUserAddInfo.ShowBirthDate = false;
            nowyUserAddInfo.ShowPhone     = false;
            nowyUserAddInfo.StatsEnabled  = statsEnabled;

            context.AdditionalUserInfo.AddObject(nowyUserAddInfo);
            context.Users.AddObject(nowyUser);
            if (context.SaveChanges() == 2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Beispiel #4
0
    public bool DodajPozycjeBudzetu(int idBudzetu, int idProduktu, int idKategorii, int?idSklepu, decimal cena, DateTime dataZakupu, decimal ilosc, string dodatkoweInfo, string userName)
    {
        using (var context = new CheaperEntities())
        {
            var select = from c in context.Budgets where c.UserID == userName && c.BudgetID == idBudzetu select c.BudgetID;
            if (select.Count() != 1)
            {
                return(false);
            }

            var nowaPozycja = new BudgetPositions();
            nowaPozycja.BudgetID       = idBudzetu;
            nowaPozycja.ProdID         = idProduktu;
            nowaPozycja.ExpenseCatID   = idKategorii;
            nowaPozycja.ShopID         = idSklepu;
            nowaPozycja.UserID         = userName;
            nowaPozycja.Price          = cena;
            nowaPozycja.PurchaseDate   = dataZakupu;
            nowaPozycja.CreationDate   = DateTime.Now;
            nowaPozycja.Quantity       = ilosc;
            nowaPozycja.AdditionalInfo = dodatkoweInfo;

            context.BudgetPositions.AddObject(nowaPozycja);

            if (context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Beispiel #5
0
    public bool DodajKatWyd(string nazwaKat, decimal kwotaKat, string userName)
    {
        using (var context = new CheaperEntities())
        {
            var nowaKatWyd = new ExpenseCategories();
            nowaKatWyd.Name   = nazwaKat;
            nowaKatWyd.Amount = kwotaKat;
            nowaKatWyd.UserID = userName;

            context.ExpenseCategories.AddObject(nowaKatWyd);
            if (context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Beispiel #6
0
    public bool DodajProdukt(string nazwaProduktu, short idKategorii, string userName)
    {
        using (var context = new CheaperEntities())
        {
            var nowyProdukt = new Products();
            nowyProdukt.Name       = nazwaProduktu;
            nowyProdukt.UserID     = userName;
            nowyProdukt.CategoryID = idKategorii;

            context.Products.AddObject(nowyProdukt);
            if (context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Beispiel #7
0
    public bool DodajBudzet(string nazwaBudzetu, string login, DateTime dataUtworzenia)
    {
        using (var context = new CheaperEntities())
        {
            var nowyBudzet = new Budgets();
            nowyBudzet.BudgetName   = nazwaBudzetu;
            nowyBudzet.CreationDate = dataUtworzenia;
            nowyBudzet.UserID       = login;

            context.Budgets.AddObject(nowyBudzet);
            if (context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Beispiel #8
0
    public bool DodajSklep(string przyjaznaNazwa, string ulica, string miasto, string kodPocztowy, string userName)
    {
        using (var context = new CheaperEntities())
        {
            var nowySklep = new Shops();
            nowySklep.FriendlyName = przyjaznaNazwa;
            nowySklep.Street       = ulica;
            nowySklep.City         = miasto;
            nowySklep.PostCode     = kodPocztowy;
            nowySklep.UserID       = userName;

            context.Shops.AddObject(nowySklep);

            if (context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }