示例#1
0
        public IHttpActionResult Post([FromBody] Order value)
        {
            try
            {
                if (value == null)
                {
                    return(BadRequest("Can't be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }


                _db.Orders.Add(value);

                _db.SaveChanges();

                return(Ok(value));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
        public IHttpActionResult PutRestaurant(int id, Restaurant restaurant)
        {
            // if (!ModelState.IsValid)
            // {
            //     return BadRequest(ModelState);
            // }

            if (id != restaurant.restaurantID)
            {
                return(BadRequest());
            }

            db.Entry(restaurant).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutUser(int id, User user)
        {
            if (id != user.UserID)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        public bool AddNote(NotesDTO newNote)
        {
            bool IsAdded = false;

            try
            {
                var ObjNote = new Note(); // class of database note table

                ObjNote.Id     = newNote.Id;
                ObjNote.Note1  = newNote.Note;
                ObjNote.UserId = newNote.UserId;

                ObjContext.Notes.Add(ObjNote);

                var NoOfRowsAffected = ObjContext.SaveChanges();

                IsAdded = NoOfRowsAffected > 0;
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return(IsAdded);
        }
示例#5
0
        public IHttpActionResult PutUser(string id, User user)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            if (id != user.Id)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Gender")] TblUser tblUser)
        {
            if (ModelState.IsValid)
            {
                db.TblUsers.Add(tblUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(null);
            //return View(tblUser);
        }
 public HttpResponseMessage create(UserDetail userdetail)
 {
     try
     {
         var response = new HttpResponseMessage();
         ue.UserDetails.Add(userdetail);
         ue.SaveChanges();
         response.StatusCode = HttpStatusCode.OK;
         return(Request.CreateResponse(HttpStatusCode.OK, userdetail));
     }
     catch
     {
         return(new HttpResponseMessage(HttpStatusCode.BadGateway));
     }
 }
示例#8
0
        public ActionResult ResetPassword(ResetPassworsModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (UserDBEntities data = new UserDBEntities())
                {
                    var user = data.Users.Where(value => value.ResetPassword == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password      = Crypto.Hash(model.NewPassword);
                        user.ResetPassword = "";
                        data.Configuration.ValidateOnSaveEnabled = false;
                        data.SaveChanges();
                        message = "New Password Updated successfully";
                    }
                }
            }
            else
            {
                message = "Somthing Invalide";
            }
            ViewBag.Message = message;
            return(View(model));
        }
示例#9
0
        public bool Register(UsersDTO newUser)
        {
            bool IsAdded = false;

            try
            {
                var ObjUser = new User(); // class of database user table

                ObjUser.Id        = newUser.Id;
                ObjUser.FirstName = newUser.FirstName;
                ObjUser.LastName  = newUser.LastName;
                ObjUser.Email     = newUser.Email;
                ObjUser.Password  = newUser.Password;
                ObjUser.UserName  = newUser.UserName;

                ObjContext.Users.Add(ObjUser);

                var NoOfRowsAffected = ObjContext.SaveChanges();

                IsAdded = NoOfRowsAffected > 0;
            }
            catch (SqlException ex)
            {
                throw ex;
            }


            return(IsAdded);
        }
示例#10
0
        public ActionResult FogertPassword(string EmailID)
        {
            //verify email
            Console.WriteLine(EmailID);
            string message = "";
            bool   status  = false;

            using (UserDBEntities dataconnect = new UserDBEntities())
            {
                var account = dataconnect.Users.Where(value => value.Email == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPassword = resetCode;
                    //
                    dataconnect.Configuration.ValidateOnSaveEnabled = status;
                    dataconnect.SaveChanges();
                    message = "Reset Password link has been sent to your email id.";
                }
                else
                {
                    message = "Account Not Found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
示例#11
0
 public ActionResult Register(UserModel objUserModel)
 {
     if (ModelState.IsValid)
     {
         if (!objUserDBEntities.Users.Any(m => m.Email == objUserModel.Email))
         {
             User objUser = new DBModel.User();
             objUser.CreateOn  = DateTime.Now;
             objUser.Email     = objUserModel.Email;
             objUser.FirstName = objUserModel.FirstName;
             objUser.LastName  = objUserModel.LastName;
             objUser.Password  = objUserModel.Password;
             objUserDBEntities.Users.Add(objUser);
             objUserDBEntities.SaveChanges();
             objUserModel = new UserModel();
             objUserModel.SuccessMessage = "Usuário Cadastrado Com Sucesso!";
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("Error", "E-Mail Já Cadastrado!");
             return(View());
         }
     }
     return(View());
 }
        public HttpResponseMessage Put([FromBody] int id, [FromUri] UserReg user)
        {
            using (UserDBEntities entities = new UserDBEntities())
            {
                try
                {
                    var entity = entities.UserRegs.FirstOrDefault(e => e.UserId == id);

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id = " + id.ToString() + " not found to update."));
                    }
                    else
                    {
                        entity.Username   = user.Username;
                        entity.Pwd        = user.Pwd;
                        entity.ConfirmPwd = user.ConfirmPwd;
                        entity.Uemail     = user.Uemail;
                        entity.Salary     = user.Salary;

                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
 public ActionResult Edit(Use use)
 {
     try
     {
         UserDBEntities db = new UserDBEntities();
         db.Entry(use).State = System.Data.Entity.EntityState.Modified;
         use.Password        = Crypto.Hash(use.Password);
         db.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
     return(RedirectToAction("EditData"));
 }
        public JsonResult Modify(string imageName)
        {
            string result = "Fail";

            UserDBEntities userDB = new UserDBEntities();

            // Upload upload = new Upload();
            Upload upload = new Upload();
            var    data   = userDB.Uploads.FirstOrDefault();

            data.ModifiedName = imageName;
            if (data.ModifiedName != null)
            {
                data.IsModified            = true;
                upload                     = data;
                userDB.Entry(upload).State = System.Data.Entity.EntityState.Modified;
                userDB.SaveChanges();
            }


            //userDB.SaveChanges();
            result = "success";



            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetPop(int id, string ImageName)
        {
            string         result = "Fail";
            UserDBEntities user   = new UserDBEntities();
            Upload         upload = new Upload();

            var model = db.Uploads.Find(id);

            model.ModifiedName = ImageName;

            if (model.ModifiedName != null)
            {
                model.IsModified         = true;
                upload                   = model;
                user.Entry(upload).State = System.Data.Entity.EntityState.Modified;
                user.SaveChanges();
                result = "successfully Modified";
            }


            //if (upload.MemberId == id)
            //{
            //    var data = user.Uploads.FirstOrDefault();
            //    return View(data);
            //}

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#16
0
 public ActionResult Register(UserModel objuserModel)
 {
     if (ModelState.IsValid)
     {
         if (!objUserDBEntities.Users.Any(m => m.Email == objuserModel.Email))
         {
             User objUser = new DBModel.User();
             objUser.CreatedOn    = DateTime.Now;
             objUser.Email        = objuserModel.Email;
             objUser.FirstName    = objuserModel.FirstName;
             objUser.LastName     = objuserModel.LastName;
             objUser.Password     = objuserModel.Password;
             objUser.YoutubeAbone = objuserModel.YoutubeAbone;
             objUser.Puan         = 100;
             objUserDBEntities.Users.Add(objUser);
             objUserDBEntities.SaveChanges();
             objuserModel = new UserModel();
             objuserModel.SuccessMessage = "User is Succesfully Added";
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("Error", "Email is Already exists!");
             return(View());
         }
     }
     return(View());
 }
        public ActionResult Delete(int id)
        {
            UserDBEntities db    = new UserDBEntities();
            var            model = db.Uses.Find(id);

            db.Uses.Remove(model);
            db.SaveChanges();
            return(RedirectToAction("EditData"));
        }
示例#18
0
 public void setPic(int id, string filename)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.Profiles
                     where (a.Id == id)
                     select a).SingleOrDefault();
         user.Pic = filename;
         context.SaveChanges();
     }
 }
示例#19
0
 public void setPAboutById(int id, string about)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.Profiles
                     where (a.Id == id)
                     select a).SingleOrDefault();
         user.About = about;
         context.SaveChanges();
     }
 }
示例#20
0
        public ActionResult Remove(int id)
        {
            UserDBEntities db   = new UserDBEntities();
            UserTable      user = db.UserTables.Where(u => u.UserID == id).Single();

            if (user != null)
            {
                db.UserTables.Remove(user);
            }
            db.SaveChanges();
            return(Customers());
        }
示例#21
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified, ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                #region //Email Exists

                var isExist = IsEmailExist(user.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion


                #region Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion
                user.IsEmailVerified = false;

                #region Save to Database
                using (UserDBEntities connect = new UserDBEntities())
                {
                    connect.Users.Add(user);
                    connect.SaveChanges();

                    //Send Email to User
                    SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString());
                    message = "Registration successfully done. Account activation link " +
                              " has been sent to your Email:" + user.Email;
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
示例#22
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified, ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //model validation
            if (ModelState.IsValid)
            {
                #region //email already exsists
                var isExist = IsEmailExsist(user.EmailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exists");
                    return(View(user));
                }
                #endregion

                #region generate activation code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region password hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion
                user.IsEmailVerified = false;

                #region save to database
                using (UserDBEntities db = new UserDBEntities())
                {
                    db.Users.Add(user);
                    db.SaveChanges();

                    //send details to user via email
                    sendverificationEmail(user.EmailID, user.ActivationCode.ToString());
                    message = "Registration successfully completed. Check your email to verify the account.";
                    Status  = true;
                }
                #endregion
            }
            else
            {
                message = "Invalied request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;


            return(View(user));
        }
示例#23
0
        public ActionResult Abone(int kullanici, string YoutubeAbone)
        {
            var x = db.Users.Find(kullanici);

            x.Puan += 10;

            var kontrol = db.Users.FirstOrDefault(a => a.YoutubeAbone == YoutubeAbone);
            var y       = db.Users.Find(kontrol.UserId);

            y.Puan -= 10;

            db.SaveChanges();
            return(View());
        }
示例#24
0
 public void setHide(int id, bool choice)
 {
     using (var context = new UserDBEntities())
     {
         var hide = (from a in context.SECURITY
                      where (a.PID == id)
                      select a).SingleOrDefault();
         if (choice == true)
             hide.VISIBILITY = true;
         if (choice == false)
             hide.VISIBILITY = false;
         context.SaveChanges();
     }
 }
示例#25
0
        public ActionResult Edit(UserEditVM user)
        {
            UserDBEntities db           = new UserDBEntities();
            UserTable      userToUpdate = db.UserTables.Where(u => u.Username == user.Username).Single();

            userToUpdate.Username  = user.Username;
            userToUpdate.Password  = user.Password;
            userToUpdate.IsAdmin   = user.IsAdmin;
            userToUpdate.Age       = user.Age;
            userToUpdate.FirstName = user.FirstName;
            userToUpdate.LastName  = user.LastName;
            db.SaveChanges();
            return(Customers());
        }
示例#26
0
 public ActionResult Register(RegisterVM user)
 {
     using (UserDBEntities db = new UserDBEntities())
     {
         if (db.UserTables.Any(x => x.Username == user.userTable.Username))
         {
             ViewBag.DuplicateMessage = "Username already exist.";
             return(View("Register", user));
         }
         db.UserTables.Add(user.userTable);
         db.SaveChanges();
     }
     ModelState.Clear();
     ViewBag.SuccessMessage = "Registration Successful.";
     return(View("Login", new LoginVM()));
 }
示例#27
0
 public ActionResult Register(UserModel objUserModel)
 {
     if (ModelState.IsValid)
     {
         User objUser = new User();
         objUser.FirstName = objUserModel.FirstName;
         objUser.LastName  = objUserModel.LastName;
         objUser.Email     = objUserModel.Email;
         objUser.Password  = objUserModel.Password;
         objUser.CreatedOn = DateTime.Now;
         objUserDBEntities.Users.Add(objUser);
         objUserDBEntities.SaveChanges();
         objUserModel.message = "successfull registered";
         return(View(objUserModel));
     }
     return(View());
 }
        public ActionResult UpdateStatusDetails(int id, bool Status)
        {
            UserDBEntities user   = new UserDBEntities();
            var            result = user.Uses.Where(e => e.Uid == id).FirstOrDefault();
            Use            use    = new Use();

            if (Status == true)
            {
                result.IsActive = false;
            }
            else
            {
                result.IsActive = true;
            }
            user.Entry(result).State = System.Data.Entity.EntityState.Modified;
            user.SaveChanges();
            return(RedirectToAction("EditData"));
        }
示例#29
0
 public ActionResult Register(UserModel objUserModel)
 {
     if (ModelState.IsValid)
     {
         User objUser = new DBModel.User();
         objUser.UserID       = objUserModel.UserID;
         objUser.UserName     = objUserModel.UserName;
         objUser.UserEmail    = objUserModel.UserEmail;
         objUser.UserImage    = objUserModel.UserImage;
         objUser.UserPassword = objUserModel.UserPassword;
         objuserDBEntities.Users.Add(objUser);
         objuserDBEntities.SaveChanges();
         // new add
         objUserModel = new UserModel();
         objUserModel.SuccessMessage = "User is sucessfully added";
         return(View("Register"));
     }
     return(View());
 }
示例#30
0
        public void Register(string _UserName, string _UserPwd, string _UserRePwd)
        {
            var a = from users in db.User select users;

            foreach (var i in a)
            {
                if (_UserName != i.UserName && _UserPwd == _UserRePwd)
                {
                    User _user = new User()
                    {
                        UserName = _UserName,
                        UserPwd  = _UserPwd,
                        Coins    = 0
                    };
                    db.User.Add(_user);
                }
            }

            db.SaveChanges();
        }
        public HttpResponseMessage Post([FromBody] UserReg user)
        {
            try
            {
                using (UserDBEntities entities = new UserDBEntities())
                {
                    entities.UserRegs.Add(user);
                    entities.SaveChanges();


                    var message = Request.CreateResponse(HttpStatusCode.Created, user);
                    message.Headers.Location = new Uri(Request.RequestUri + user.UserId.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
示例#32
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (UserDBEntities db = new UserDBEntities())
            {
                db.Configuration.ValidateOnSaveEnabled = false;

                var v = db.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    db.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalied Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
        public ActionResult Register(UserModel1 um)
        {
            SignUpPage sp = new SignUpPage();

            sp.Password  = um.Password;
            sp.UserId    = um.UserId;
            sp.FirstName = um.FirstName;
            sp.LastName  = um.LastName;
            sp.Gender    = um.Gender;
            sp.DOB       = DateTime.Parse(um.DOB);
            sp.Address   = um.Address;
            context.SignUpPages.Add(sp);
            context.SaveChanges();
            um = new UserModel1();


            if (ModelState.IsValid == true)
            {
                ViewData["msg"] = "<script>alert('Your details are submitted successfully')</script>";
                ModelState.Clear();
            }
            return(View(um));
        }
示例#34
0
        /// <summary>
        /// Lägger till en användare i databasen
        /// </summary>
        public void insertUser(Profiles profile, SECURITY security)
        {
            try
            {
                using (var context = new UserDBEntities())
                {
                    context.Database.Connection.Open();
                    context.Profiles.Add(profile);
                    context.SaveChanges();
                    security.PID = profile.Id;
                    context.SECURITY.Add(security);
                    context.SaveChanges();
                    
                }
            }
            catch (Exception e)
            {

            }

        }
示例#35
0
 public void UpdatePassword(int id, string newpass)
 {
     using (var context = new UserDBEntities())
     {
         var user = (from a in context.SECURITY
                     where (a.PID == id)
                     select a).SingleOrDefault();
         user.PASSWORD = newpass;
         context.SaveChanges();
     }
 }