コード例 #1
0
 public IHttpActionResult UpdateNote(string seflink, [FromBody] NOTE note)
 {
     try
     {
         int id = UserInf.GetUser();
         using (MynoteDBEntities db = new MynoteDBEntities())
         {
             var gnote = db.NOTES.FirstOrDefault(x => x.NoteSefLink == seflink);
             if (gnote != null)
             {
                 if (note.NoteCategoryId != null)
                 {
                     gnote.NoteTitle        = note.NoteTitle;
                     gnote.NoteDescription  = note.NoteDescription;
                     gnote.NoteContent      = note.NoteContent;
                     gnote.NoteCategoryId   = note.NoteCategoryId;
                     gnote.NoteModifiedDate = note.NoteModifiedDate;
                     gnote.NoteModifiedId   = id;
                     int result = db.SaveChanges();
                     if (result != 0)
                     {
                         return(Ok());
                     }
                     else
                     {
                         return(BadRequest());
                     }
                 }
                 else
                 {
                     gnote.NoteTitle             = note.NoteTitle;
                     gnote.NoteDescription       = note.NoteDescription;
                     gnote.NoteContent           = note.NoteContent;
                     gnote.privateNoteCategoryId = note.privateNoteCategoryId;
                     gnote.NoteModifiedDate      = note.NoteModifiedDate;
                     gnote.NoteModifiedId        = id;
                     int result = db.SaveChanges();
                     if (result != 0)
                     {
                         return(Ok());
                     }
                     else
                     {
                         return(BadRequest());
                     }
                 }
             }
             else
             {
                 return(NotFound());
             }
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #2
0
 public IHttpActionResult DeleteNote(int id)
 {
     using (MynoteDBEntities db = new MynoteDBEntities())
     {
         try
         {
             var result = db.NOTES.FirstOrDefault(x => x.Id == id);
             if (result == null)
             {
                 return(NotFound());
             }
             else
             {
                 result.isActive = 0;
                 int save = db.SaveChanges();
                 if (save != 0)
                 {
                     return(Ok());
                 }
                 else
                 {
                     return(BadRequest());
                 }
             }
         }
         catch (Exception e)
         {
             return(BadRequest(e.Message));
         }
     }
 }
コード例 #3
0
        public IHttpActionResult AddUserFriend(int id)
        {
            int userid = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    FRIEND friend = new FRIEND
                    {
                        FromUserId = userid,
                        ToUserId   = id,
                        StatusCode = 0
                    };
                    db.FRIENDS.Add(friend);
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
コード例 #4
0
        public IHttpActionResult MyPublishUpdate([FromBody] PUBLICATION publish, int id)
        {
            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.PUBLICATIONS.FirstOrDefault(x => x.Id == id);
                    if (result == null)
                    {
                        return(BadRequest());
                    }

                    result.PubContent      = publish.PubContent;
                    result.PubTitle        = publish.PubTitle;
                    result.PubModifiedDate = DateTime.Now;
                    result.PubSefLink      = publish.PubSefLink;
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
コード例 #5
0
        public IHttpActionResult CreateCategory(CATEGOR category)
        {
            int id = UserInf.GetUser();

            try
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    category.UserId = id;
                    db.CATEGORS.Add(category);
                    int result = db.SaveChanges();
                    if (result != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #6
0
 public IHttpActionResult Update(string sef, [FromBody] CATEGOR category)
 {
     try
     {
         int id = UserInf.GetUser();
         using (MynoteDBEntities db = new MynoteDBEntities())
         {
             var result = db.CATEGORS.FirstOrDefault(x => x.UserId == id && x.Seflink == sef);
             if (result != null)
             {
                 result.CategoryName = category.CategoryName;
                 int feed = db.SaveChanges();
                 if (feed != 0)
                 {
                     return(Ok());
                 }
                 else
                 {
                     return(BadRequest());
                 }
             }
             else
             {
                 return(BadRequest());
             }
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #7
0
        public IHttpActionResult OkRequest(int id)
        {
            int userid = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var friend = db.FRIENDS.FirstOrDefault(x => x.ToUserId == userid && x.FromUserId == id && x.StatusCode == 0);
                    if (friend == null)
                    {
                        return(BadRequest());
                    }
                    else
                    {
                        friend.StatusCode = 1;
                        int save = db.SaveChanges();
                        if (save != 0)
                        {
                            return(Ok());
                        }
                        else
                        {
                            return(BadRequest());
                        }
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
コード例 #8
0
        public async Task <IHttpActionResult> FilesCreate(int publishid)
        {
            int           userid         = UserInf.GetUser();
            List <string> path           = new List <string>();
            var           fileuploadPath = HttpContext.Current.Server.MapPath("~/UploadedFilesPublish");
            var           multiFormDataStreamProvider = new MultiFileUploadProvider(fileuploadPath);
            await Request.Content.ReadAsMultipartAsync(multiFormDataStreamProvider);

            path = multiFormDataStreamProvider.FileData.Select(x => x.LocalFileName).ToList();
            foreach (var item in path)
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    FILE file = new FILE
                    {
                        PublishId   = publishid,
                        FileName    = Path.GetFileName(item),
                        UserId      = userid,
                        CreatedTime = DateTime.Now,
                        FilePath    = item,
                        IsActive    = 1
                    };
                    db.FILES.Add(file);
                    db.SaveChanges();
                }
            }

            return(Ok());
        }
コード例 #9
0
        public IHttpActionResult AddMyPublish([FromBody] PUBLICATION publish)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    publish.PubUserId = id;
                    db.PUBLICATIONS.Add(publish);
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
コード例 #10
0
        public IHttpActionResult DeleteMyFriend(int id)
        {
            int userid = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.FRIENDS.FirstOrDefault(x => x.ToUserId == userid && x.FromUserId == id);
                    db.FRIENDS.Remove(result);
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
コード例 #11
0
        public IHttpActionResult AddComment([FromBody] PUBLICATIONSCOMMENT comment)
        {
            int userid = UserInf.GetUser();

            comment.CommentUserId = userid;
            comment.CommentDate   = DateTime.Now;
            comment.isActive      = 1;
            try
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    db.PUBLICATIONSCOMMENTS.Add(comment);
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #12
0
        public async Task <IHttpActionResult> ImageCreate(int notid)
        {
            int           userid         = UserInf.GetUser();
            List <string> path           = new List <string>();
            var           fileuploadPath = HttpContext.Current.Server.MapPath("~/UploadedFiles");
            var           multiFormDataStreamProvider = new MultiFileUploadProvider(fileuploadPath);
            await Request.Content.ReadAsMultipartAsync(multiFormDataStreamProvider);

            path = multiFormDataStreamProvider.FileData.Select(x => x.LocalFileName).ToList();
            foreach (var item in path)
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    IMAGE img = new IMAGE
                    {
                        ImagePath   = item,
                        ImageName   = Path.GetFileName(item),
                        NotId       = notid,
                        UserId      = userid,
                        CreatedDate = DateTime.Now
                    };
                    db.IMAGES.Add(img);
                    db.SaveChanges();
                }
            }

            return(Ok());
        }
コード例 #13
0
 public IHttpActionResult DeleteMyPublish(int id)
 {
     using (MynoteDBEntities db = new MynoteDBEntities())
     {
         var result = db.PUBLICATIONS.FirstOrDefault(x => x.Id == id);
         result.isActive = 0;
         int save = db.SaveChanges();
         if (save != 0)
         {
             return(Ok());
         }
         else
         {
             return(BadRequest());
         }
     }
 }
コード例 #14
0
 public IHttpActionResult DeleteShare(int userid, int notid)
 {
     using (MynoteDBEntities db = new MynoteDBEntities())
     {
         var result = db.SHARES.FirstOrDefault(x => x.ToUserId == userid && x.NotId == notid);
         result.IsActive = 0;
         int save = db.SaveChanges();
         if (save != 0)
         {
             return(Ok());
         }
         else
         {
             return(BadRequest());
         }
     }
 }
コード例 #15
0
        public IHttpActionResult UpdateProfil([FromBody] USER user)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.USERS.FirstOrDefault(x => x.Id == id);
                    if (result == null)
                    {
                        return(BadRequest());
                    }
                    else
                    {
                        PassManagement ps      = new PassManagement();
                        byte[]         salt    = ps.Hashing(user.Mail);
                        string         hashing = ps.HashPass(user.Hash, salt);
                        result.Hash        = hashing;
                        result.Mail        = user.Mail;
                        result.UpdatedDate = DateTime.Now;
                        result.UserName    = user.UserName;
                        result.Name        = user.Name;
                        int save = db.SaveChanges();
                        if (save != 0)
                        {
                            return(Ok());
                        }
                        else
                        {
                            return(BadRequest());
                        }
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
コード例 #16
0
        public IHttpActionResult Share([FromBody] SHARE share)
        {
            int fromuserID = UserInf.GetUser();

            try
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    if (fromuserID == share.ToUserId)
                    {
                        return(BadRequest());
                    }
                    if (db.SHARES.Any(x => x.ToUserId == share.ToUserId && x.FromUserıd == fromuserID && x.NotId == share.NotId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        share.FromUserıd        = fromuserID;
                        share.Share_CreatedDate = DateTime.Now;
                        share.IsActive          = 1;
                        db.SHARES.Add(share);
                        int feed = db.SaveChanges();
                        if (feed != 0)
                        {
                            return(Ok());
                        }
                        else
                        {
                            return(BadRequest());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #17
0
        public IHttpActionResult CreateNote(NOTE note)
        {
            int id = UserInf.GetUser();

            try
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    note.NoteUserId = id;
                    db.NOTES.Add(note);
                    int feed = db.SaveChanges();
                    if (feed != 0)
                    {
                        return(Ok());
                    }
                    return(BadRequest());
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #18
0
 public IHttpActionResult RegisterUser(USER model)
 {
     if (model == null)
     {
         return(BadRequest("Geçersiz kullanıcı"));
     }
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         PassManagement ps      = new PassManagement();
         byte[]         salt    = ps.Hashing(model.Mail);
         string         hashing = ps.HashPass(model.Hash, salt);
         model.Hash         = hashing;
         model.RegisterDate = DateTime.Now;
         using (MynoteDBEntities ent = new MynoteDBEntities())
         {
             ent.USERS.Add(model);
             int result = ent.SaveChanges();
             if (result != 0)
             {
                 return(Ok("Kullanıcı başarıyla kaydedilmiştir"));
             }
             else
             {
                 return(BadRequest("Kullanıcı kaydı başarısız"));
             }
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }