public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (AspContext dc = new AspContext())
            {
                dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                                                                // Confirm password does not match issue on save changes
                var v = dc.AspNetUsers.Where(a => a.Id == id).FirstOrDefault();
                if (v != null)
                {
                    v.IsEnable = "true";
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    v.IsEnable = "true";
                }
                dc.SaveChanges();
                Status = true;
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
        public ActionResult saveuser(int id, string propertyName, string value)
        {
            var status  = false;
            var message = "";

            //Update data to database
            using (AspContext dc = new AspContext())
            {
                var user = dc.UserProfiles.Find(id);
                if (user != null)
                {
                    dc.Entry(user).Property(propertyName).CurrentValue = value;
                    dc.SaveChanges();
                    status = true;
                }
                else
                {
                    message = "Error!";
                }
            }

            var     response = new { value = value, status = status, message = message };
            JObject o        = JObject.FromObject(response);

            return(Content(o.ToString()));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Company course = db.Companies.Find(id);

            db.Companies.Remove(course);
            db.SaveChanges();
            return(RedirectToAction("Index", "Manage"));
        }
Пример #5
0
 public User AddComments(User user)
 {
     try
     {
         var res = _aspContext.User.Add(user);
         _aspContext.SaveChanges();
         return(res.Entity);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Пример #6
0
 public Comments AddComments(Comments comments)
 {
     try
     {
         var res = _aspContext.Comments.Add(comments);
         _aspContext.SaveChanges();
         return(res.Entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #7
0
 public Post AddPost(Post post)
 {
     try
     {
         var res = _aspContext.Post.Add(post);
         _aspContext.SaveChanges();
         return(res.Entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #8
0
 public Vote AddVote(Vote vote)
 {
     try
     {
         var res = _aspContext.Vote.Add(vote);
         _aspContext.SaveChanges();
         return(res.Entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult CompanyCreate(Company company)
        {
            if (ModelState.IsValid)
            {
                Company user = null;
                using (AspContext db = new AspContext())
                {
                    user = db.Companies /*.Include(p => p.AspNetUser)*/.FirstOrDefault(u => u.ID == company.ID);
                }

                /* if (user == null)
                 * {
                 */
                using (AspContext db = new AspContext())
                {
                    var id = User.Identity.GetUserId();
                    db.Companies.Add(new Company {
                        tName = company.tName, Description = company.Description, Tematic = company.Tematic, aspNetUser = id                           /*aspNetUser=new AspNetUser()*/
                    });
                    db.SaveChanges();

                    user = db.Companies.Where(u => u.tName == company.tName && u.Description == company.Description && u.Tematic == company.Tematic && u.aspNetUser == id).FirstOrDefault();
                }

                if (user != null)
                {
                    return(RedirectToAction("Index", "Manage"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Пользователь с таким логином уже существует");
            }


            return(View(company));
        }
Пример #10
0
 public void Insert(T entity)
 {
     _entities.Add(entity);
     _context.SaveChanges();
 }