Esempio n. 1
0
        public async Task <IActionResult> Follow(String myUser, String followUser)
        {
            var followQuery = _db.Follows.Where(follow => myUser == follow.User && followUser == follow.Follows);

            if (myUser == followUser)
            {
                return(new JsonResult(new { status = "sameUser" }));
            }

            if (!followQuery.Any())
            {
                var follower = new Follow
                {
                    User    = myUser,
                    Follows = followUser
                };

                _db.Follows.Add(follower);
                _db.SaveChanges();

                return(new JsonResult(new { status = "follow" }));
            }
            else
            {
                _db.Follows.Remove(followQuery.Single());
                _db.SaveChanges();
                return(new JsonResult(new { status = "unfollow" }));
            }
        }
Esempio n. 2
0
        public ActionResult Edit(Role role, string MemberListSelect)
        {
            if (ModelState.IsValid)
            {
                //取得資料庫裏面原來的值
                var roleItem = db.Roles.Single(r => r.Id == role.Id);

                //套用新的值
                db.Entry(roleItem).CurrentValues.SetValues(role);


                //放入新的值
                roleItem.Members.Clear();
                string[] strArray    = MemberListSelect.Split(',');
                var      memberLists = db.Members.ToList().Where(c => strArray.Contains(c.Id.ToString()));
                foreach (var m in memberLists)
                {
                    roleItem.Members.Add(m);
                }

                db.Entry(roleItem).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Edit"));
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Member member = db.Members.Find(id);

            db.Members.Remove(member);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public async Task <IActionResult> addpost([FromBody] PostPayload postPayload)
        {
            var post = new Post();

            post.UserName  = postPayload.UserName;
            post.imageLink = postPayload.imgLink;
            post.text      = postPayload.text;

            _db.Posts.Add(post);
            _db.SaveChanges();

            return(Ok(new { status = true }));
        }
        public ActionResult <User> Register([FromBody] RegisterPayload registerPayload)
        {
            try
            {
                MailAddress m = new MailAddress(registerPayload.Email);
            }
            catch (Exception ex)
            {
                return(new JsonResult(new { status = "false", message = "email format " + registerPayload.Email }));
            }


            try
            {
                var existingUserWithMail = _db.Users
                                           .Any(u => u.Email == registerPayload.Email);
                var existingUserWithUserName = _db.Users
                                               .Any(u => u.UserName == registerPayload.UserName);

                if (existingUserWithMail)
                {
                    return(Conflict(new { status = false, message = "Email Exists" }));
                }
                if (existingUserWithUserName)
                {
                    return(Conflict(new { status = false, message = "UserName already exists." }));
                }

                var userToCreate = new User
                {
                    Email        = registerPayload.Email,
                    UserName     = registerPayload.UserName,
                    PasswordHash = BCrypt.Net.BCrypt.HashPassword(registerPayload.Password),
                    Gender       = registerPayload.Gender,
                    Role         = "SimpleUser",
                };

                _db.Users.Add(userToCreate);



                _db.SaveChanges();

                return(Ok(new { status = true, user = userToCreate, firstname = registerPayload.UserName }));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new { status = "false", message = "" + ex.Message }));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Servicio que agrega un autor a un paper.
 /// </summary>
 /// <param name="IdentificadorPaper"></param>
 /// <param name="autor"></param>
 /// <returns>Lista de Personas</returns>
 public void AddAutorToPaper(string IdentificadorPaper, Autor autor)
 {
     BackendContext.Papers
     .Where(p => p.IdentificadorPaper == IdentificadorPaper)
     .First().Autores.Add(autor);
     BackendContext.SaveChanges();
 }
Esempio n. 7
0
        public static object DeleteFile(object json)
        {
            var body   = Helper.Decode(json);
            var fileId = int.Parse(body["fileId"]);
            var userId = int.Parse(body["userId"]);

            using (var context = new BackendContext())
            {
                var queryFile = context.File.Where(file => file.Id == fileId);
                if (!queryFile.Any())
                {
                    return(Helper.Error(404, "未找到文件"));
                }
                var queryUser = context.Users.Where(u => u.Id == userId);
                if (!queryUser.Any())
                {
                    return(Helper.Error(404, "未找到用户"));
                }
                var theFile = queryFile.Single();

                if (theFile.Project.Users.All(u => u.Id != userId))
                {
                    return(Helper.Error(403, "用户未参加该项目"));
                }
                if (theFile.UserId != userId &&
                    theFile.Project.UserPermissons.Single(p => p.UserId == userId).Permission == Permission.Participant)
                {
                    return(Helper.Error(401, "权限不足"));
                }
                context.File.Remove(theFile);
                context.SaveChanges();
                return(Helper.BuildResult(null));
            }
        }
Esempio n. 8
0
        public static object PostFile(object json, HttpPostedFile file)
        {
            var body      = Helper.Decode(json);
            var userId    = int.Parse(body["userId"]);
            var projectId = int.Parse(body["projectId"]);
            var name      = body["name"];
            var stream    = file.InputStream;
            var bytes     = new byte[stream.Length];

            stream.Read(bytes, 0, bytes.Length);
            using (var context = new BackendContext())
            {
                var newFile = new File()
                {
                    Name       = name,
                    Content    = bytes,
                    UploadTime = DateTime.Now,
                    UserId     = userId,
                    ProjectId  = projectId
                };
                context.File.Add(newFile);
                context.SaveChanges();
                var result = new
                {
                    id   = newFile.Id,
                    name = newFile.Name
                };
                return(Helper.BuildResult(result));
            }
        }
Esempio n. 9
0
        public static object DeleteProject(object json)
        {
            var body      = Helper.Decode(json);
            var projectId = int.Parse(body["projectId"]);
            var ownerId   = int.Parse(body["ownerId"]);

            using (var context = new BackendContext())
            {
                var queryUser = context.Users.Where(user => user.Id == ownerId);
                if (!queryUser.Any())
                {
                    return(Helper.Error(404, "用户不存在"));
                }

                var queryProject = context.Projects.Where(project => project.Id == projectId);
                if (!queryProject.Any())
                {
                    return(Helper.Error(404, "项目不存在"));
                }

                var theProject = queryProject.Single();
                if (theProject.OwnerId != ownerId)
                {
                    return(Helper.Error(401, "该用户未拥有该项目"));
                }

                context.Projects.Remove(theProject);
                context.SaveChanges();

                return(Helper.BuildResult(null));
            }
        }
Esempio n. 10
0
        public static object Login(object json)
        {
            //获取输入
            var body     = Helper.Decode(json);
            var email    = body["email"];
            var password = body["password"];

            using (var context = new BackendContext())
            {
                //查询&验证
                var query = context.Users.Where(user => user.Email == email && user.Password == password);
                if (!query.Any())
                {
                    return(Helper.Error(401, "邮箱或密码错误"));
                }

                //修改&保存
                var theUser = query.Single();
                theUser.GenerateToken();
                context.SaveChanges();

                //返回
                var data = new
                {
                    id     = theUser.Id,
                    token  = theUser.Token,
                    name   = theUser.UserInfo.Name,
                    avatar = theUser.UserInfo.Avatar
                };
                return(Helper.BuildResult(data));
            }
        }
Esempio n. 11
0
        public static object SetAvatar(object json)
        {
            var body   = Helper.Decode(json);
            var id     = int.Parse(body["id"]);
            var avatar = body["avatar"];

            using (var context = new BackendContext())
            {
                var query = context.Users.Where(user => user.Id == id);
                if (!query.Any())
                {
                    return(Helper.Error(404, "该用户不存在"));
                }
                var theUser = query.Single();
                var theInfo = theUser.UserInfo;
                theInfo.Avatar = "data:image/png;base64," + avatar;
                context.SaveChanges();
                var data = new
                {
                    id     = theUser.Id,
                    name   = theInfo.Name,
                    avatar = theInfo.Avatar
                };
                return(Helper.BuildResult(data));
            }
        }
Esempio n. 12
0
        public static object ChangePassword(object json)
        {
            var body         = Helper.Decode(json);
            var id           = int.Parse(body["userId"]);
            var passwordFrom = body["passwordFrom"];
            var passwordTo   = body["passwordTo"];

            using (var context = new BackendContext())
            {
                var query = context.Users.Where(user => user.Id == id && user.Password == passwordFrom);
                if (!query.Any())
                {
                    return(Helper.Error(401, "密码错误"));
                }

                var theUser = query.Single();
                theUser.Password = passwordTo;
                theUser.GenerateToken();
                context.SaveChanges();

                var data = new
                {
                    token = theUser.Token
                };
                return(Helper.BuildResult(data));
            }
        }
Esempio n. 13
0
        public static object CreateSubTask(object json)
        {
            var body = Helper.DecodeToObject(json);

            using (var context = new BackendContext())
            {
                var content = body["subtaskContent"].ToString();
                var taskId  = int.Parse(body["taskId"].ToString());
                var userId  = int.Parse(body["userId"].ToString());

                var query = context.Users.Where(user => user.Id == userId);
                if (!query.Any())
                {
                    return(Helper.Error(401, "userId不存在"));
                }

                var queryTask = context.Tasks.Where(task => task.Id == taskId);
                if (!queryTask.Any())
                {
                    return(Helper.Error(404, "任务不存在"));
                }

                var theTask = queryTask.Single();


                var flag = userId == theTask.OwnerId;

//                if (!Helper.CheckPermission(theTask.Progress.ProjectId, userId, flag, OperationType.POST))
//                {
//                    return Helper.Error(401, "无权限");
//                }
                var newSubTask = new Subtask
                {
                    Content = content,
                    State   = false,
                    UserId  = userId,
                    TaskId  = theTask.Id
                };
                newSubTask.User = query.Single();

                context.Subtasks.Add(newSubTask);

                theTask.Subtasks.Add(newSubTask);
                context.SaveChanges();

                RecordTaskOperation(userId, taskId, "创建了子任务:" + newSubTask.Content);


                var data = new
                {
                    subtaskId      = newSubTask.Id,
                    subtaskContent = newSubTask.Content,
                    taskId         = newSubTask.TaskId,
                    state          = newSubTask.State,
                    executorId     = newSubTask.UserId
                };
                return(Helper.BuildResult(data));
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Metodo que agrega una revista
        /// </summary>
        /// <param name="revista">revista a agregar</param>
        public void Add(Revista revista)
        {
            //Guardo la revista en el Backend.
            BackendContext.Revistas.Add(revista);

            //Guardo los cambios.
            BackendContext.SaveChanges();
        }
Esempio n. 15
0
        public ActionResult DeleteConfirmed(int id)
        {
            News news = db.News.Find(id);

            db.News.Remove(news);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        public ActionResult DeleteConfirmed(int id)
        {
            Service service = db.Services.Find(id);

            db.Services.Remove(service);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 17
0
        /// <summary>
        /// Metodo que agrega un indice de impacto.
        /// </summary>
        /// <param name="impactoIndice">Indice de impacto a agregar</param>
        public void Add(ImpactoIndice impactoIndice)
        {
            // Guardo el autor en el Backend
            BackendContext.ImpactoIndices.Add(impactoIndice);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 18
0
        public ActionResult DeleteConfirmed(int id)
        {
            Cases cases = db.Cases.Find(id);

            db.Cases.Remove(cases);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 19
0
        /// <summary>
        /// Servicio que agrega Grado.
        /// </summary>
        public void AddGrado(Grado grado)
        {
            // Guardo el Grado en el Backend
            BackendContext.Grados.Add(grado);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 20
0
        public void AddPaper(Paper paper)
        {
            // Guardo el paper en el Backend
            BackendContext.Papers.Add(paper);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 21
0
        public void Add(Persona persona)
        {
            // Guardo la Persona en el Backend
            BackendContext.Personas.Add(persona);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 22
0
        public void AddPublicaciones(Publicacion publicacion)
        {
            // Guardo la Publicacion en el Backend
            BackendContext.Publicaciones.Add(publicacion);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 23
0
        public void AddAutor(Autor autor)
        {
            // Guardo el Autor en el Backend
            BackendContext.Autores.Add(autor);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
 public void vaciarPublicaciones()
 {
     foreach (var entity in BackendContext.Publicaciones)
     {
         BackendContext.Publicaciones.Remove(entity);
         BackendContext.SaveChanges();
     }
 }
Esempio n. 25
0
        public void AddEstadoPostulacion(EstadoDePostulacion estadoPostulacion)
        {
            // Guardo el paper en el Backend
            BackendContext.EstadosdePostulaciones.Add(estadoPostulacion);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
        public void addPublicacion(Publicacion p)
        {
            // Guardo la Persona en el Backend
            BackendContext.Publicaciones.Add(p);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 27
0
        public void Add(Documento documento)
        {
            // Guardo la Persona en el Backend
            BackendContext.Documento.Add(documento);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
Esempio n. 28
0
        public ActionResult DeleteConfirmed(int id)
        {
            Unit unit = db.Units.Find(id);

            db.Units.Remove(unit);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 29
0
        public ActionResult Sort(string sortData, int Id)
        {
            if (!string.IsNullOrEmpty(sortData))
            {
                string[] tempDatas = sortData.TrimEnd(',').Split(',');
                foreach (string tempData in tempDatas)
                {
                    string[]    itemDatas   = tempData.Split(':');
                    CaseDiagram casediagram = db.CaseDiagrams.Find(Convert.ToInt16(itemDatas[0]));
                    casediagram.ListNum = Convert.ToInt16(itemDatas[1]);

                    //db.Entry(publish).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Edit", "Cases", new { Id = Id, type = "2" }));
        }
Esempio n. 30
0
        public ActionResult Sort(string sortData)
        {
            if (!string.IsNullOrEmpty(sortData))
            {
                string[] tempDatas = sortData.TrimEnd(',').Split(',');
                foreach (string tempData in tempDatas)
                {
                    string[]        itemDatas       = tempData.Split(':');
                    CaseServiceArea caseservicearea = db.CaseServiceAreas.Find(Convert.ToInt16(itemDatas[0]));
                    caseservicearea.ListNum = Convert.ToInt16(itemDatas[1]);

                    //db.Entry(publish).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }