Esempio n. 1
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));
            }
        }
Esempio n. 2
0
        public IHttpActionResult MyFriend()
        {
            int           id   = UserInf.GetUser();
            HashSet <int> list = new HashSet <int>();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                if (db.FRIENDS.Any(x => x.ToUserId == id && x.StatusCode == 1))
                {
                    var result = db.FRIENDS.Where(x => x.ToUserId == id && x.StatusCode == 1).Select(x => new { x.FromUserId }).ToList();
                    foreach (var item in result)
                    {
                        list.Add(item.FromUserId);
                    }
                }
                if (db.FRIENDS.Any(x => x.FromUserId == id && x.StatusCode == 1))
                {
                    var result = db.FRIENDS.Where(x => x.FromUserId == id && x.StatusCode == 1).Select(x => new { x.ToUserId }).ToList();
                    foreach (var item in result)
                    {
                        list.Add(item.ToUserId);
                    }
                }
                list.Remove(id);
                if (list.Count != 0)
                {
                    var users = db.USERS.Where(x => list.Contains(x.Id)).Select(x => new { x.Id, x.UserName, x.Name }).ToList();
                    return(Ok(users));
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Esempio n. 3
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));
            }
        }
Esempio n. 4
0
        public IHttpActionResult GetMyFrienReq()
        {
            HashSet <int> list = new HashSet <int>();
            int           id   = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.FRIENDS.Where(x => x.ToUserId == id && x.StatusCode == 0).Select(x => new { x.FromUserId }).ToList();
                    foreach (var item in result)
                    {
                        list.Add(item.FromUserId);
                    }
                    if (list.Count != 0)
                    {
                        var request = db.USERS.Where(x => list.Contains(x.Id)).Select(x => new { x.Id, x.Name, x.UserName }).ToList();
                        return(Ok(request));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 5
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));
                }
            }
        }
Esempio n. 6
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));
                }
            }
        }
Esempio n. 7
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());
        }
Esempio n. 8
0
        public IHttpActionResult UpdateUserMailCheck(string mail)
        {
            int    id        = UserInf.GetUser();
            string checkmail = mail.Replace(",com", ".com");

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                if (db.USERS.Any(x => x.Mail == checkmail))
                {
                    var result = db.USERS.FirstOrDefault(x => x.Mail == checkmail);
                    if (result.Id == id)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    return(Ok());
                }
            }
        }
Esempio n. 9
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());
        }
Esempio n. 10
0
        public IHttpActionResult UserCategory()
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.CATEGORS.Where(x => x.UserId == id && x.isActive == 1).Select(x => new { x.Id, x.UserId, x.CategoryName, x.Seflink }).ToList();
                    if (result.Count != 0)
                    {
                        return(Ok(result));
                    }


                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 11
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));
     }
 }
Esempio n. 12
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));
                }
            }
        }
Esempio n. 13
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));
                }
            }
        }
Esempio n. 14
0
        public IHttpActionResult GetMyPublish()
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.PUBLICATIONS.Where(x => x.PubUserId == id && x.isActive == 1).Select
                                     (x => new { x.Id, x.PubTitle, x.PubUserId, x.PubContent, x.PubCreatedDate, x.PubModifiedDate, x.isActive, x.PubSefLink }).ToList();
                    if (result.Count != 0)
                    {
                        return(Ok(result));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 15
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));
     }
 }
Esempio n. 16
0
        public IHttpActionResult GetFriendPublish()
        {
            HashSet <int> liste = new HashSet <int>();
            int           id    = UserInf.GetUser();

            try
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    var result = db.FRIENDS.Where(x => x.FromUserId == id || x.ToUserId == id).Select(x => new
                    {
                        x.Id,
                        x.FromUserId,
                        x.ToUserId,
                        x.StatusCode
                    }).ToList();
                    foreach (var item in result)
                    {
                        if (item.StatusCode == 1)
                        {
                            liste.Add(item.ToUserId);
                            liste.Add(item.FromUserId);
                        }
                    }
                    liste.Remove(id);
                    var pubresult = db.PUBLICATIONS.Where(x => liste.Contains(x.PubUserId) && x.isActive == 1)
                                    .Select(x => new Models.DbModel.Publish
                    {
                        PublishId           = x.Id,
                        PublisherId         = x.PubUserId,
                        PublisherName       = x.USER.Name,
                        PublisherUserName   = x.USER.UserName,
                        PublishContent      = x.PubContent,
                        PublishTitle        = x.PubTitle,
                        PublishModifiedTime = x.PubModifiedDate,
                        PublishTime         = x.PubCreatedDate,
                        PublishIsActive     = x.isActive,
                        PublishSef          = x.PubSefLink,
                    }).OrderByDescending(x => x.PublishTime).ToList();
                    if (pubresult.Count != 0)
                    {
                        return(Ok(pubresult));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 17
0
        public IHttpActionResult GetUserShareh()
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    if (db.SHARES.Any(x => x.FromUserıd == id || x.ToUserId == id))
                    {
                        var result = db.SHARES.Where(x => x.FromUserıd == id && x.IsActive == 1 && x.NOTE.isActive == 1).
                                     Select(x => new Models.DbModel.Share
                        {
                            Id                    = x.NotId,
                            NoteTitle             = x.NOTE.NoteTitle,
                            NoteContent           = x.NOTE.NoteContent,
                            NoteDescription       = x.NOTE.NoteDescription,
                            NoteCreatedDate       = x.NOTE.NoteCreatedDate,
                            NoteSefLink           = x.NOTE.NoteSefLink,
                            privateNoteCategoryId = x.NOTE.privateNoteCategoryId,
                            NoteCategoryId        = x.NOTE.NoteCategoryId,
                            NoteUserId            = x.NOTE.NoteUserId,
                            isActive              = x.NOTE.isActive,
                            NoteModifiedDate      = x.NOTE.NoteModifiedDate,
                            NoteModifiedId        = x.NOTE.NoteModifiedId,
                            CategoryName          = x.NOTE.SYSTEMCATEGOR.Name,
                            PCategoryName         = x.NOTE.CATEGOR.CategoryName,
                            ModifiedName          = x.NOTE.USER1.Name,
                            FromUserName          = x.USER1.Name
                        }).OrderByDescending(x => x.NoteCreatedDate).GroupBy(x => x.Id).ToList();
                        var gidecek = result.Select(q => q.First());
                        if (gidecek.ToList().Count == 0)
                        {
                            return(BadRequest());
                        }
                        else
                        {
                            return(Ok(gidecek));
                        }
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 18
0
        public IHttpActionResult GetAddFriend(string username)
        {
            string tusername = username.Trim();
            int    id        = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try {
                    var result = db.USERS.FirstOrDefault(x => x.UserName == tusername);
                    if (result == null)
                    {
                        return(Content(HttpStatusCode.NotFound, "Böyle bir kullanıcı bulunamadı"));
                    }
                    else
                    {
                        if (id != result.Id)
                        {
                            var sonuc = db.FRIENDS.FirstOrDefault(x => (x.ToUserId == id && x.FromUserId == result.Id) || (x.ToUserId == result.Id && x.FromUserId == id));
                            if (sonuc == null)
                            {
                                var user = db.USERS.Where(x => x.Id == result.Id).Select(x => new { x.Id, x.Name, x.UserName }).ToList();
                                return(Content(HttpStatusCode.Accepted, user.FirstOrDefault()));
                            }
                            else
                            {
                                if (sonuc.StatusCode == 0)
                                {
                                    var user = db.USERS.Where(x => x.Id == result.Id).Select(x => new { x.Id, x.Name, x.UserName }).ToList();
                                    return(Content(HttpStatusCode.Created, user.FirstOrDefault()));
                                }
                                else
                                {
                                    var user = db.USERS.Where(x => x.Id == result.Id).Select(x => new { x.Id, x.Name, x.UserName }).ToList();
                                    return(Content(HttpStatusCode.OK, user.FirstOrDefault()));
                                }
                            }
                        }
                        else
                        {
                            return(Content(HttpStatusCode.NoContent, "Kendini ekleyemezsin"));
                        }
                    }
                } catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 19
0
        public IHttpActionResult GetNote()
        {
            int id = UserInf.GetUser();

            try
            {
                using (MynoteDBEntities db = new MynoteDBEntities())
                {
                    var result = db.NOTES.Where(x => x.NoteUserId == id && x.isActive == 1).
                                 Select(x => new Models.DbModel.Note
                    {
                        Id                    = x.Id,
                        NoteTitle             = x.NoteTitle,
                        NoteContent           = x.NoteContent,
                        NoteDescription       = x.NoteDescription,
                        NoteCreatedDate       = x.NoteCreatedDate,
                        NoteSefLink           = x.NoteSefLink,
                        privateNoteCategoryId = x.privateNoteCategoryId,
                        NoteCategoryId        = x.NoteCategoryId,
                        Name                  = x.USER.Name,
                        NoteUserId            = x.NoteUserId,
                        isActive              = x.isActive,
                        NoteModifiedDate      = x.NoteModifiedDate,
                        NoteModifiedId        = x.NoteModifiedId,
                        CategoryName          = x.SYSTEMCATEGOR.Name,
                        PCategoryName         = x.CATEGOR.CategoryName
                    }).OrderByDescending(x => x.NoteCreatedDate).ToList();


                    if (result.Count != 0)
                    {
                        return(Ok(result));
                    }
                    else
                    {
                        return(BadRequest("Bu id'ye ait not bulunmamaktadır"));
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 20
0
        public IHttpActionResult GetUpdateNote(string seflink)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                var result = db.NOTES.Where(x => x.NoteSefLink == seflink)
                             .Select(x => new
                                     { x.Id, x.NoteContent, x.NoteTitle, x.NoteUserId, x.NoteDescription, x.NoteCreatedDate,
                                       x.NoteModifiedId, x.NoteModifiedDate, x.NoteSefLink, x.NoteCategoryId, x.privateNoteCategoryId }).ToList();
                if (result.Count == 0)
                {
                    return(BadRequest());
                }
                else
                {
                    return(Ok(result.FirstOrDefault()));
                }
            }
        }
Esempio n. 21
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));
                }
            }
        }
Esempio n. 22
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));
            }
        }
Esempio n. 23
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));
            }
        }
Esempio n. 24
0
        public IHttpActionResult GeUserProfil()
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.USERS.Where(x => x.Id == id).Select(x => new { x.Id, x.UserName, x.Name, x.Mail, x.Hash }).ToList();
                    if (result.Count != 0)
                    {
                        return(Ok(result.FirstOrDefault()));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 25
0
        public IHttpActionResult UpdateUserNameCheck(string username)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                if (db.USERS.Any(x => x.UserName == username))
                {
                    var result = db.USERS.FirstOrDefault(x => x.UserName == username);
                    if (result.Id == id)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    return(Ok());
                }
            }
        }
Esempio n. 26
0
        public IHttpActionResult ShareUsers(int notid)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                var result = db.SHARES.Where(x => x.FromUserıd == id && x.NotId == notid && x.IsActive == 1).Select(x => new Models.DbModel.ShUs
                {
                    UserId    = x.ToUserId,
                    UserName  = x.USER.UserName,
                    Name      = x.USER.Name,
                    ShareDate = x.Share_CreatedDate,
                    NotId     = x.NotId
                }).OrderByDescending(x => x.ShareDate).ToList();
                if (result.Count != 0)
                {
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest());
                }
            }
        }