public void Update(UpdateUserDTO entity, int id) { var user = _unitOfWork.User.Get(id); if (!String.IsNullOrEmpty(entity.FirstName)) { user.FirstName = entity.FirstName; } if (!String.IsNullOrEmpty(entity.LastName)) { user.LastName = entity.LastName; } if (!String.IsNullOrEmpty(entity.Password)) { user.Password = Compute256Hash.ComputeSha256Hash(entity.Password); } if (!String.IsNullOrEmpty(entity.Email)) { user.Email = entity.Email; } if (entity.IsDeleted == 0 || entity.IsDeleted == 1) { user.IsDeleted = entity.IsDeleted; } if (entity.RoleId == 1 || entity.RoleId == 2) { user.RoleId = entity.RoleId; } user.ModifiedAt = DateTime.Now; _unitOfWork.Save(); }
public string Login(LoginDTO data, IConfiguration config) { if (String.IsNullOrEmpty(data.Email)) { throw new Exception("Email field is required!"); } if (String.IsNullOrEmpty(data.Password)) { throw new Exception("Password field is required!"); } if (!data.Email.Contains("@")) { throw new Exception("Enter valid email!"); } data.Password = Compute256Hash.ComputeSha256Hash(data.Password); var valid = _unitOfWork.User.Find(u => u.Password == data.Password && u.Email == data.Email && u.IsDeleted == 0).FirstOrDefault(); if (valid != null) { var token = GenerateToken.GenerateJSONWebToken(valid, config); return(token); } else { throw new Exception("User not found"); } }
public int Register(RegisterDTO data) { if (String.IsNullOrEmpty(data.FirstName)) { throw new Exception("First name is required"); } if (String.IsNullOrEmpty(data.LastName)) { throw new Exception("Last name is required"); } if (String.IsNullOrEmpty(data.Email)) { throw new Exception("email name is required"); } if (String.IsNullOrEmpty(data.Password)) { throw new Exception("Password name is required"); } if (!data.Email.Contains("@")) { throw new Exception("Emmail is not in good forma"); } data.Password = Compute256Hash.ComputeSha256Hash(data.Password); var user = new User { FirstName = data.FirstName, LastName = data.LastName, Email = data.Email, Password = data.Password, RoleId = 2 }; _unitOfWork.User.Add(user); _unitOfWork.Save(); var userId = user.Id; _unitOfWork.Wallet.Add(new Wallet { UserId = userId, Balance = 0.00 }); _unitOfWork.Save(); return(userId); }
public ActionResult Create(IFormCollection collection) { try { var user = new UpdateUserDTO { FirstName = collection["FirstName"], LastName = collection["LastName"], Email = collection["Email"], Password = Compute256Hash.ComputeSha256Hash(collection["Password"]) }; _userService.Insert(user); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
static void Main(string[] args) { using (var unitOfWork = new UnitOfWork(new RestaurantContext())) { //adding Categories List <Dish> dishes = new List <Dish>(); string[] cats = new String[] { "Corbe", "Salate", "Rostil", "Pice" }; //roles unitOfWork.Role.Add(new Role { Name = "admin", CreatedtAt = DateTime.Now }); unitOfWork.Role.Add(new Role { Name = "user", CreatedtAt = DateTime.Now }); unitOfWork.Save(); //categories for (var i = 0; i < cats.Length; i++) { var category = new Category { Name = cats[i] }; unitOfWork.Category.Add(category); } unitOfWork.Save(); //users unitOfWork.User.Add(new User { CreatedtAt = DateTime.Now, Email = "*****@*****.**", FirstName = "Admin", IsDeleted = 0, LastName = "Admin", Password = Compute256Hash.ComputeSha256Hash("admin"), RoleId = 1 }); unitOfWork.User.Add(new User { CreatedtAt = DateTime.Now, Email = "*****@*****.**", FirstName = "Korinsik", IsDeleted = 0, LastName = "Korisnik", Password = Compute256Hash.ComputeSha256Hash("korisnik"), RoleId = 2 }); unitOfWork.Wallet.Add(new Wallet { UserId = 1, Balance = 0.00 }); unitOfWork.Wallet.Add(new Wallet { UserId = 2, Balance = 0.00 }); #region FakeData Category and Dishes //corbe dishes.Add(new Dish() { Title = "Govedja", Ingredients = "govedje meso", Price = 350.00, Serving = "500 ml", Image = "govedja-corba.jpg", CategoryId = 1 } ); dishes.Add(new Dish() { Title = "Pileca", Ingredients = "pilece meso", Price = 250.00, Serving = "450 ml", Image = "pileca-corba.jpg", CategoryId = 1 } ); dishes.Add(new Dish() { Title = "Juneca", Ingredients = "junece meso", Price = 550.00, Serving = "350 ml", Image = "juneca-corba.jpg", CategoryId = 1 } ); //predjela dishes.Add(new Dish() { Title = "Ruska salata", Ingredients = "pilece meso,majonez,grasak", Price = 150.00, Serving = "150 gr", Image = "ruska-salata.jpg", CategoryId = 2 } ); dishes.Add(new Dish() { Title = "vitaminska salata", Ingredients = "vitamini", Price = 1800.00, Serving = "50 gr", Image = "vitaminska_salata.jpg", CategoryId = 2 } ); dishes.Add(new Dish() { Title = "Sopska salata", Ingredients = "neki sastojci", Price = 165.00, Serving = "200 gr", Image = "sopska-salata.jpg", CategoryId = 2 } ); //rostilj dishes.Add(new Dish() { Title = "Pecelje :)", Ingredients = "pilece meso,majonez,grasak", Price = 850.00, Serving = "350 gr", Image = "pecenje.jpg", CategoryId = 3 } ); dishes.Add(new Dish() { Title = "Kobasice", Ingredients = "jeste i bice", Price = 550, Serving = "250 gr", Image = "kobasice.jpg", CategoryId = 3 } ); dishes.Add(new Dish() { Title = "Cevapi", Ingredients = "meso", Price = 165.00, Serving = "450 gr", Image = "cevapi.jpg", CategoryId = 3 } ); //pice dishes.Add(new Dish() { Title = "Tubotg", Ingredients = "ladno", Price = 250.00, Serving = "0.8 l", Image = "tuborg.jpg", CategoryId = 4 } ); dishes.Add(new Dish() { Title = "Vinjak", Ingredients = "kokain", Price = 50, Serving = "0.03 l", Image = "vinjak.jpg", CategoryId = 4 } ); dishes.Add(new Dish() { Title = "Rakija", Ingredients = "prepecenica ljuta", Price = 00.00, Serving = "0.03 l", Image = "rakija.jpg", CategoryId = 4 } ); foreach (var dish in dishes) { unitOfWork.Dish.Add(dish); } #endregion unitOfWork.Save(); Console.WriteLine("Done"); } }