public IHttpActionResult PutDepartment(int id, Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.DeptID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
 public IHttpActionResult postEmployee(Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Employees.Add(employee);
         db.SaveChanges();
         return(Ok(employee));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Example #3
0
        // Add New Employee

        public IHttpActionResult PostEmployee(Employee employee)
        {
            if (employee == null)
            {
                return(BadRequest());
            }
            else
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(Created("Employee Class", employee));
            }
        }
Example #4
0
        // Add New Department

        public IHttpActionResult PostDepartment(Department department)
        {
            if (department == null)
            {
                return(BadRequest());
            }
            else
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(Created("Employee Class", department));
            }
        }
Example #5
0
 public dynamic Create(dynamic _Obj, dynamic _Para = null)
 {
     try
     {
         Product product = _Obj;
         MyEF.Products.Add(product);
         MyEF.SaveChanges();
         return(ReturnCode.Success);
     }
     catch (Exception ex)
     {
         return(ReturnCode.Fail);
     }
 }
Example #6
0
 public dynamic Create(dynamic _Obj, dynamic _Para = null)
 {
     try
     {
         Member member = _Obj;
         MyEF.Members.Add(member);
         MyEF.SaveChanges();
         return(ReturnCode.Success);
     }
     catch (Exception ex)
     {
         return(ReturnCode.Fail);
     }
 }
Example #7
0
        public ActionResult Registration(User user)
        {
            bool   Status  = false;
            string message = "";

            //Model validation
            if (ModelState.IsValid)
            {
                var emailIsExist = IsEmailExist(user.EmailID);
                if (emailIsExist)
                {
                    ModelState.AddModelError("EmailExists", "Email already exists.");
                    return(View());
                }
                //Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);

                //save to DB
                using (MyDataBaseEntities dc = new MyDataBaseEntities())
                {
                    {
                        dc.Users.Add(user);
                        dc.SaveChanges();
                    }
                }
            }
            else
            {
                message = "Invalid Request";
            }
            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Example #8
0
        public void DeleteStudent(int id)
        {
            var db      = new MyDataBaseEntities();
            var student = db.Student.Find(id);

            db.Student.Remove(student);
            db.SaveChanges();
        }
        public ActionResult DeleteReader(int id)
        {
            MyDataBaseEntities dc = new MyDataBaseEntities();

            var readerId = dc.Reader.Find(id);

            dc.Reader.Remove(readerId);
            dc.SaveChanges();
            return(RedirectToAction("ReaderList", "Reader"));
        }
Example #10
0
 public ActionResult AddOrEdit(Emp empModel)
 {
     using (MyDataBaseEntities dbmodel = new MyDataBaseEntities())
     {
         dbmodel.Emps.Add(empModel);
         dbmodel.SaveChanges();
     }
     ModelState.Clear();
     ViewBag.SuccessMessage = "Regestration Successfully";
     return(View(" AddOrEdit", new Emp()));
 }
Example #11
0
        public void UpdateStudent(int id, string name, DateTime birthday, int class_id)
        {
            var db      = new MyDataBaseEntities();
            var student = db.Student.Find(id);

            student.Name     = name;
            student.Birthday = birthday;
            student.Class_id = class_id;

            db.Entry(student).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
        }
Example #12
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified, ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //Modelvalidation
            if (ModelState.IsValid)
            {
                #region //Email is already Exist or not
                var isExist = IsEmailExist(user.EmailID);
                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  Sava data to Database
                using (MyDataBaseEntities dc = new MyDataBaseEntities())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

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

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Example #13
0
        public void CreateStudent(string code, string name, DateTime birthday, int class_id)
        {
            var student = new Student();

            student.Code     = code;
            student.Name     = name;
            student.Birthday = birthday;
            student.Class_id = class_id;

            var db = new MyDataBaseEntities();

            db.Student.Add(student);
            db.SaveChanges();
        }
Example #14
0
        public ActionResult Reader(Reader reader)
        {
            MyDataBaseEntities dc = new MyDataBaseEntities();
            var model             = dc.ReadingLog.ToList();

            try
            {
                dc.Reader.Add(reader);
                dc.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }

            return(RedirectToAction("ReaderList", "Reader"));
        }
Example #15
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (MyDataBaseEntities dc = new MyDataBaseEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false;  //This is the line i have added here to avoid confirm password does not match issue on save changes
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
        public ActionResult Add(User usermodel)
        {
            using (MyDataBaseEntities dbmodel = new MyDataBaseEntities())
            {
                if (dbmodel.User.Any(x => x.UserName == usermodel.UserName))
                {
                    log.Info(usermodel.UserName + " already exists");
                    ViewBag.DuplicateMessage = "Username already exists";
                    return(View("Add", new User()));
                }

                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                byte[] sel = new byte[4];
                rng.GetBytes(sel);
                usermodel.Salt      = Convert.ToBase64String(sel);
                usermodel.Password += usermodel.Salt;

                //hachage Password
                var crypt = new SHA256Managed();
                var hash  = new StringBuilder();

                byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(usermodel.Password));
                foreach (byte theByte in crypto)
                {
                    hash.Append(theByte.ToString("x2"));
                }

                //change password to hash password
                usermodel.Password        = hash.ToString();
                usermodel.ConfirmPassword = usermodel.Password;

                dbmodel.User.Add(usermodel);
                dbmodel.SaveChanges();
                log.Info(usermodel.UserName + " Success Registration");
                ViewBag.SuccessMessage = "Success Registration";
                return(View(new User()));
            }
        }
        public ActionResult Create(ReadingLog readingLog)
        {
            string bookName   = readingLog.BookName;
            string authorName = readingLog.Author;

            readingLog.ClockIn    = DateTime.Now;
            readingLog.ClockOut   = DateTime.Now;
            readingLog.ReaderId   = Convert.ToInt32(Session["ReaderId"]);
            readingLog.ReaderName = Convert.ToString(Session["ReaderName"]);
            int Id = Convert.ToInt32(Session["ReaderId"]);

            using (MyDataBaseEntities dc = new MyDataBaseEntities())
            {
                dc.ReadingLog.Add(readingLog);
                dc.SaveChanges();
                var readingLogList = dc.ReadingLog.Where(a => a.ReaderId == Id).ToList();
                //var BookList = (readingLogList.Select(a => a.BookName)).ToList();
                //dc.ReadingLog.Where(a => a.ReaderId == readingLog.ReaderId).Select(a =>a.BookName).ToList();
                //return Redirect(ReaderDetails);
                //Console.Write(BookList);
                return(View("BookList", readingLogList));
            }
        }