Exemplo n.º 1
0
        public async Task <Dictionary <string, object> > GetMyNotes(CommonRequest _input)
        {
            Dictionary <string, object> jsonObj = new Dictionary <string, object>();

            try
            {
                using (var _DbEntity = new adelankanotesContext())
                {
                    var notes = _DbEntity.Mynotes.Where(x => x.UserId == _input.Id && x.IsDeleted == false && x.IsActive == true).ToList();
                    if (notes != null)
                    {
                        jsonObj.Add("Code", 0);
                        jsonObj.Add("Status", "Success");
                        jsonObj.Add("Message", "Data fetched!");
                        jsonObj.Add("Data", notes);
                    }
                    else
                    {
                        jsonObj.Add("Code", 1);
                        jsonObj.Add("Status", "Fail");
                        jsonObj.Add("Message", $"Something went wrong!");
                        jsonObj.Add("Data", null);
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObj.Add("Code", 1);
                jsonObj.Add("Status", "Fail");
                jsonObj.Add("Message", $"{ex.InnerException?.Message}");
                jsonObj.Add("Data", null);
            }
            return(await Task.FromResult(jsonObj));
        }
Exemplo n.º 2
0
        public async Task <Dictionary <string, object> > LoginUser(User _input, string secretKey)
        {
            Dictionary <string, object> jsonObj = new Dictionary <string, object>();

            try
            {
                using (var _DbEntity = new adelankanotesContext())
                {
                    var _username = Encoding.ASCII.GetString(Convert.FromBase64String(_input.Username));
                    var _password = Encoding.ASCII.GetString(Convert.FromBase64String(_input.Password));

                    var user = _DbEntity.Users.Where(x => x.IsDeleted == false && x.Username.Equals(_username) && x.Password.Equals(_password)).FirstOrDefault();
                    if (user != null)
                    {
                        var tokenHandler    = new JwtSecurityTokenHandler();
                        var key             = Encoding.ASCII.GetBytes(secretKey);
                        var tokenDescriptor = new SecurityTokenDescriptor
                        {
                            Subject = new ClaimsIdentity(new Claim[]
                            {
                                new Claim(ClaimTypes.Name, user.UserId.ToString())
                            }),
                            Expires            = DateTime.UtcNow.AddDays(7),
                            SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key),
                                                                        SecurityAlgorithms.HmacSha256Signature)
                        };

                        var token = tokenHandler.CreateToken(tokenDescriptor);
                        var resp  = new
                        {
                            userId = user.UserId,
                            token  = tokenHandler.WriteToken(token)
                        };

                        jsonObj.Add("Code", 0);
                        jsonObj.Add("Status", "Success");
                        jsonObj.Add("Message", "Valid User");
                        jsonObj.Add("Data", resp);
                    }
                    else
                    {
                        jsonObj.Add("Code", 1);
                        jsonObj.Add("Status", "Fail");
                        jsonObj.Add("Message", "Invalid User");
                        jsonObj.Add("Data", null);
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObj.Add("Code", 1);
                jsonObj.Add("Status", "Fail");
                jsonObj.Add("Message", $"{ex.Message}");
                jsonObj.Add("Data", null);
            }

            return(await Task.FromResult(jsonObj));
        }
Exemplo n.º 3
0
        public async Task <Dictionary <string, object> > CreateComment(Comment _input)
        {
            Dictionary <string, object> jsonObj = new Dictionary <string, object>();

            try
            {
                using (var _DbEntity = new adelankanotesContext())
                {
                    if (_input != null)
                    {
                        _input.CreatedDate  = DateTime.Now;
                        _input.ModifiedDate = DateTime.Now;

                        _DbEntity.Comments.Add(_input);
                        _DbEntity.SaveChanges();

                        jsonObj.Add("Code", 0);
                        jsonObj.Add("Status", "Success");
                        jsonObj.Add("Message", "Note Saved!");
                        jsonObj.Add("Data", null);
                    }
                    else
                    {
                        jsonObj.Add("Code", 1);
                        jsonObj.Add("Status", "Fail");
                        jsonObj.Add("Message", $"Something went wrong!");
                        jsonObj.Add("Data", null);
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObj.Add("Code", 1);
                jsonObj.Add("Status", "Fail");
                jsonObj.Add("Message", $"{ex.InnerException?.Message}");
                jsonObj.Add("Data", null);
            }
            return(await Task.FromResult(jsonObj));
        }
Exemplo n.º 4
0
        public async Task <Dictionary <string, object> > GetAllCommentForNote(CommonRequest _input)
        {
            Dictionary <string, object> jsonObj = new Dictionary <string, object>();

            try
            {
                using (var _DbEntity = new adelankanotesContext())
                {
                    var comments = (from c in _DbEntity.Comments join u in _DbEntity.Users on c.UserId equals u.UserId
                                    where c.NoteId == _input.Id && c.IsDeleted == false
                                    select new { c.CommentContent, u.Username }
                                    ).ToList();

                    if (comments != null)
                    {
                        jsonObj.Add("Code", 0);
                        jsonObj.Add("Status", "Success");
                        jsonObj.Add("Message", "Data fetched!");
                        jsonObj.Add("Data", comments);
                    }
                    else
                    {
                        jsonObj.Add("Code", 1);
                        jsonObj.Add("Status", "Fail");
                        jsonObj.Add("Message", $"Something went wrong!");
                        jsonObj.Add("Data", null);
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObj.Add("Code", 1);
                jsonObj.Add("Status", "Fail");
                jsonObj.Add("Message", $"{ex.InnerException?.Message}");
                jsonObj.Add("Data", null);
            }
            return(await Task.FromResult(jsonObj));
        }