Ejemplo n.º 1
0
 //Johan Sakshaug
 //returns true if case was submitted successfully, false if not
 //redo Tetiana
 public bool SubmitCase(SkjemaDTO inCase)
 {
     try
     {
         using (var db = new SvarbotDbSys())
         {
             var f = new Form()
             {
                 Id           = inCase.Id,
                 Navn         = inCase.Username,
                 SBNummer     = inCase.SBnumber,
                 RegionBygg   = inCase.Location,
                 Beskrivelse  = inCase.Message,
                 AntallBerort = inCase.UserNr,
                 CategoryId   = inCase.CategoryId,
                 Date         = DateTime.Now
             };
             db.Form.Add(f);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
 //Johan Sakshaug
 //toggle a subcategory as favorite
 public void ToggleFavorite(string username, int subCategoryId)
 {
     using (var db = new SvarbotDbSys())
     {
         var favorite = db.Favorites.SingleOrDefault(f => f.Brukernavn == username && f.UndercategoryId == subCategoryId);
         if (favorite == null)
         {
             Favorites favoriteToAdd = new Favorites
             {
                 Brukernavn      = username,
                 UndercategoryId = subCategoryId
             };
             db.Favorites.Add(favoriteToAdd);
         }
         else
         {
             db.Favorites.Remove(favorite);
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        //Johan Sakshaug
        //Registers a user in the database. Returns true if successful, false if not
        public bool RegistrerUser(UserDTO inUser)
        {
            using (var db = new SvarbotDbSys())
            {
                try
                {
                    var newUser = new Accounts();
                    newUser.navn = inUser.username;
                    byte[] passwordDb = MakeHash(inUser.password);
                    newUser.passord = passwordDb;

                    db.Accounts.Add(newUser);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 4
0
        //Tetiana lagrer i db antall klikk på kategorier
        public bool SaveClickCount(ClickCountDTO clickIn)
        {
            try
            {
                var clickedOn = new ClickCount
                {
                    Username    = clickIn.Username,
                    CategoryId  = clickIn.CategoryId,
                    DateClicked = clickIn.ClickDate,
                    IsMainCat   = clickIn.IsMainCat
                };
                _dbContext.ClickCount.Add(clickedOn);
                _dbContext.SaveChanges();
                return(true);
            }

            catch (Exception)
            {
                return(false);
            }
        }