Пример #1
0
        public async Task <IActionResult> DeleteAsync(int id)
        {
            var     userClaims = User.Claims;
            var     UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            AppUser appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            MateItem ExistingmateItem = _dbContext.MateItems.Where(mi => mi.Id == id && mi.Owner == appUser).FirstOrDefault();

            if (ExistingmateItem == null)
            {
                return(NotFound($"Could not found an item you are looking for(Are you sure you are the owner of the item?)"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Submitted wrong data!"));
            }

            //_dbContext.MateItems.Remove(ExistingmateItem);
            _dbContext.Entry(ExistingmateItem).State = EntityState.Deleted;
            //_dbContext.SaveChanges();
            await _dbContext.SaveChangesAsync();

            return(Ok("Data deleted!"));
        }
        private void NotifyAdminAndPostOwnerOfUpdatedPost(MateItem newmateItem)
        {
            MailAddress AdminAddress   = new MailAddress(Utilities.ADMINMAILADDRESS);
            MailAddress AdOwnerAddress = new MailAddress(newmateItem.Owner.Email);

            var newPostLink = $"{Request.Scheme}://{Request.Host}/state/{newmateItem.ItemState}/{newmateItem.ItemCategory}/{newmateItem.Id}";

            using (SmtpClient smtpClient = new SmtpClient(Utilities.MAILSERVERHOST, Utilities.MAILSERVERPORT))
            {
                smtpClient.Credentials = new System.Net.NetworkCredential(Utilities.MAILSERVERUSERNAME, Utilities.MAILSERVERPASSWORD);
                smtpClient.Timeout     = 2000000;
                using (MailMessage msg = new MailMessage())
                {
                    msg.From       = new MailAddress(Utilities.MAILSERVERUSERNAME, Utilities.DISPLAYNAME);
                    msg.IsBodyHtml = true;
                    msg.To.Add(AdminAddress);
                    msg.Subject = "Admin there is an updated post to check";
                    msg.Body    = $"Admin<br/><br/><a href={newPostLink}>{newPostLink}</a><br /><br /> has been updated. Check and confirm it's content{Utilities.MESSAGEFOOTER}";
                    smtpClient.Send(msg);
                }

                using (MailMessage msg2 = new MailMessage())
                {
                    msg2.From       = new MailAddress(Utilities.MAILSERVERUSERNAME, Utilities.DISPLAYNAME);
                    msg2.IsBodyHtml = true;
                    msg2.To.Add(AdOwnerAddress);
                    msg2.Bcc.Add(AdminAddress);
                    msg2.Subject = $"Your updated ad  {newmateItem.Title} has been received and  is under review";
                    msg2.Body    = $"Hi {newmateItem.Owner.Firstname},<br/><br/> We are reviewing your updated ad <b>{newmateItem.Title}</b>.<br /><br /> Note that this ad will be suspended until the updated content is approved.{Utilities.MESSAGEFOOTER}";

                    smtpClient.Send(msg2);
                }
            }
        }
Пример #3
0
        public IActionResult Put(int id, [FromBody] MateItem mateItem)
        {
            var     userClaims = User.Claims;
            var     UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            AppUser appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            MateItem ExistingmateItem = _dbContext.MateItems.Where(mi => mi.Id == id && mi.Owner == appUser).FirstOrDefault();

            if (ExistingmateItem == null)
            {
                return(NotFound($"Could not found an item you are looking for(Are you sure you are the owner of the item?)"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Submitted wrong data!"));
            }

            ////////////////////////////////////////////////////////////////////////////////////////
            ExistingmateItem.Title        = mateItem.Title ?? ExistingmateItem.Title;
            ExistingmateItem.Description  = mateItem.Description ?? ExistingmateItem.Description;
            ExistingmateItem.ItemCategory = mateItem.ItemCategory ?? ExistingmateItem.ItemCategory;
            ExistingmateItem.ItemState    = mateItem.ItemState ?? ExistingmateItem.ItemState;
            ExistingmateItem.Owner        = mateItem.Owner ?? ExistingmateItem.Owner;
            ///////////////////////////////////////////////////////////////////////////////////////

            _dbContext.Entry(ExistingmateItem).State = EntityState.Modified;
            _dbContext.SaveChanges();

            string newUri = Url.Link("GetMateItem", new { id = ExistingmateItem.Id });

            return(Created(newUri, ExistingmateItem));
        }
Пример #4
0
        private void NotifyAdminAndPostOwnerOfNewPost(MateItem newmateItem)
        {
            MailAddress AdminAddress   = new MailAddress(Utilities.ADMINMAILADDRESS);
            MailAddress AdOwnerAddress = new MailAddress(newmateItem.Owner.Email);

            var newPostLink = $"{Request.Scheme}://{Request.Host}/state/{newmateItem.ItemState}/{newmateItem.ItemCategory}/{newmateItem.Id}";

            using (SmtpClient smtpClient = new SmtpClient(Utilities.MAILSERVERHOST, Utilities.MAILSERVERPORT))
            {
                smtpClient.Credentials = new System.Net.NetworkCredential(Utilities.MAILSERVERUSERNAME, Utilities.MAILSERVERPASSWORD);
                smtpClient.Timeout     = 2000000;
                using (MailMessage msg = new MailMessage())
                {
                    msg.From       = new MailAddress(Utilities.MAILSERVERUSERNAME, Utilities.DISPLAYNAME);
                    msg.IsBodyHtml = true;
                    msg.To.Add(AdminAddress);
                    msg.Subject = "Admin there is a new post to confirm";
                    msg.Body    = $"Admin<br/><br/><a href={newPostLink}>{newPostLink}</a><br /><br /> is waiting for your confirmation{Utilities.MESSAGEFOOTER}";
                    smtpClient.Send(msg);
                }

                using (MailMessage msg2 = new MailMessage())
                {
                    msg2.From       = new MailAddress(Utilities.MAILSERVERUSERNAME, Utilities.DISPLAYNAME);
                    msg2.IsBodyHtml = true;
                    msg2.To.Add(AdOwnerAddress);
                    msg2.Bcc.Add(AdminAddress);
                    msg2.Subject = $"Your ad  {newmateItem.Title} has been received and  is under review";
                    msg2.Body    = $"Hi {newmateItem.Owner.Firstname},<br/><br/> We are reviewing your ad <b>{newmateItem.Title}</b> and will have it approved and published if it passes neccesary checks.{Utilities.MESSAGEFOOTER}";

                    smtpClient.Send(msg2);
                }
            }
        }
Пример #5
0
        public void PostNewItemPhotos(int itemid, IFormFile file, IFormCollection frmcoll)
        {
            var     userClaims = User.Claims;
            var     UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            AppUser appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            MateItem ExistingmateItem = _dbContext.MateItems.Where(mi => mi.Id == itemid && mi.Owner == appUser).FirstOrDefault();
        }
        public IActionResult SendMessageToUser([FromBody] UserMessage msg, int mateItemId, int receiverId, string msgType)
        {
            if (User == null)
            {
                return(NotFound("Sender is not logged in, check your internet connection."));
            }
            var userClaims = User.Claims;
            var UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            //int senderId = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault().Id;
            AppUser  sender     = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();
            AppUser  receiver   = _dbContext.AppUsers.Where(appusr => appusr.Id == receiverId).FirstOrDefault();
            MateItem miMsgOwner = _dbContext.MateItems.Where(mi => mi.Id == mateItemId).FirstOrDefault();

            //AppUser appUserReceiver = _dbContext.AppUsers.Where(appusr => appusr.Id == receiverId).FirstOrDefault();

            if (!ModelState.IsValid)
            {
                return(BadRequest("Message content is in a bad format!"));
            }
            msg.Sender      = sender;
            msg.Receiver    = receiver;
            msg.ForMateItem = miMsgOwner;
            msg.SenderId    = sender.Id;
            msg.TitleExtractedFromItemTitle = $"Re:{miMsgOwner.Title}";

            //receiver.Messages.Add(msg);
            _dbContext.UserMessages.Add(msg);
            _dbContext.SaveChanges();

            string mateItemTitle = _dbContext.MateItems.Find(mateItemId).Title;

            //Send email to the receiver of this message.
            using (SmtpClient smtpClient = new SmtpClient(Utilities.MAILSERVERHOST, Utilities.MAILSERVERPORT))
            {
                smtpClient.Credentials = new System.Net.NetworkCredential(Utilities.MAILSERVERUSERNAME, Utilities.MAILSERVERPASSWORD);
                smtpClient.Timeout     = 2000000;
                using (MailMessage mailMsg = new MailMessage())
                {
                    mailMsg.From       = new MailAddress(Utilities.MAILSERVERUSERNAME, Utilities.DISPLAYNAME);
                    mailMsg.IsBodyHtml = true;
                    mailMsg.To.Add(receiver.Email);
                    if (msgType == "new")
                    {
                        mailMsg.Subject = "You have a new message";
                        mailMsg.Body    = $"{sender.Firstname} {sender.Lastname} contacted you for the ad <b>{mateItemTitle}</b>. <br/><br/>Login to your dashboard to read the message{Utilities.MESSAGEFOOTER}";
                    }
                    else
                    {
                        mailMsg.Subject = $"{sender.Firstname} {sender.Lastname} has replied your message";
                        mailMsg.Body    = $"{sender.Firstname} {sender.Lastname} has replied your message for ad <b>{mateItemTitle}</b>. <br/><br/>Login to your dashboard to read the message{Utilities.MESSAGEFOOTER}";
                    }

                    smtpClient.Send(mailMsg);
                }
            }

            return(Ok("Message sent successfully"));
        }
        public IActionResult GetSpecificUserPost(int mateItemId)
        {
            var userClaims = User.Claims;
            var UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            var appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            MateItem mateItem = _dbContext.MateItems.Where(mi => mi.AppUserId == appUser.Id && mi.Id == mateItemId).FirstOrDefault();

            return(Ok(mateItem));
        }
Пример #8
0
 private static void ManuallyAssignOwnerToRelatedItems(MateItem foundMateItem, List <MateItem> relatedItems)
 {
     if (relatedItems.Count > 0)
     {
         foreach (var item in relatedItems)
         {
             item.Owner = foundMateItem.Owner;
         }
     }
 }
Пример #9
0
        private void NotifyPostOwnerAndAdminOfApprovalState(MateItem mateItemToChangeItsApprovedState, int approvalStateId)
        {
            var adOwnerEmailAddress = mateItemToChangeItsApprovedState.Owner.Email;

            using (SmtpClient smtpClient = new SmtpClient(Utilities.MAILSERVERHOST, Utilities.MAILSERVERPORT))
            {
                smtpClient.Credentials = new System.Net.NetworkCredential(Utilities.MAILSERVERUSERNAME, Utilities.MAILSERVERPASSWORD);
                smtpClient.Timeout     = 2000000;

                using (MailMessage msg = new MailMessage())
                {
                    MailAddress adOwnerAddress = new MailAddress(adOwnerEmailAddress);
                    MailAddress AdminAddress   = new MailAddress(Utilities.ADMINMAILADDRESS);

                    msg.To.Add(adOwnerAddress);
                    msg.Bcc.Add(AdminAddress);
                    msg.From       = new MailAddress(Utilities.MAILSERVERUSERNAME, Utilities.DISPLAYNAME);
                    msg.IsBodyHtml = true;


                    //$"{this.Request.Scheme}://{this.Request.MAILSERVERHOST}
                    var newPostLink = $"{Request.Scheme}://{Request.Host}/state/{mateItemToChangeItsApprovedState.ItemState}/{mateItemToChangeItsApprovedState.ItemCategory}/{mateItemToChangeItsApprovedState.Id}";



                    if (approvalStateId == 1)
                    {
                        msg.Subject = $"Your ad {mateItemToChangeItsApprovedState.Title} has been approved";
                        msg.Body    = $"Congratulation your ad <a href={newPostLink}>{mateItemToChangeItsApprovedState.Title}</a> has been approved{Utilities.MESSAGEFOOTER}";
                    }
                    else
                    {
                        msg.Subject = $"Your ad {mateItemToChangeItsApprovedState.Title} has been disapproved";
                        msg.Body    = $"Your ad <a href={newPostLink}>{mateItemToChangeItsApprovedState.Title}</a><br /> contains somed unwanted contents and has been disapproved{Utilities.MESSAGEFOOTER}";
                    }

                    //smtpClient.EnableSsl = true;
                    smtpClient.Send(msg);
                }
            }
        }
        public IActionResult DeleteSpecificUserPost(int mateItemId)
        {
            var userClaims = User.Claims;
            var UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            var appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            MateItem mateItem = _dbContext.MateItems.Where(mi => mi.AppUserId == appUser.Id && mi.Id == mateItemId).FirstOrDefault();

            //Get the photos related to this MateItem
            List <Photo> photos = _dbContext.Photos.ToList();

            foreach (var item in photos)
            {
                if (mateItem.ItemPhotos.Any(itmph => itmph.Id == item.Id))
                {
                    //First remove the Images of this removed photo
                    System.IO.File.Delete(Path.Combine(_hostingEnv.WebRootPath, $"Uploads/{item.Filename}"));
                    //Then
                    _dbContext.Photos.Remove(item);
                }
            }

            ////TODO:Also remove saved items with this mateItem.Id(This SavedItems class does not exist yet, create it.)
            //List<MateItem> savedMateItems = _dbContext.SavedItems.Where(svditms => svditms.MateItemId == mateItem.Id).ToList();
            //_dbContext.SavedEvents.RemoveRange(savedMateItems);

            _dbContext.MateItems.Remove(mateItem);
            _dbContext.SaveChanges();

            var msg = new
            {
                delmsg = $"Successfully removed {mateItem.Title}"
            };

            return(Ok(msg));
        }
        public IActionResult EditSpecificUserPost(int mateItemId, MateItem mateItem)
        {
            var userClaims = User.Claims;
            var UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            var appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            MateItem ExistingmateItem = _dbContext.MateItems.Where(mi => mi.AppUserId == appUser.Id && mi.Id == mateItemId).FirstOrDefault();

            if (ExistingmateItem == null)
            {
                return(NotFound($"Could not found an item you are looking for(Are you sure you are the owner of the item?)"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Submitted wrong data!"));
            }

            ////////////////////////////////////////////////////////////////////////////////////////
            ExistingmateItem.Title        = mateItem.Title ?? ExistingmateItem.Title;
            ExistingmateItem.Description  = mateItem.Description ?? ExistingmateItem.Description;
            ExistingmateItem.ItemCategory = mateItem.ItemCategory ?? ExistingmateItem.ItemCategory;
            ExistingmateItem.ItemState    = mateItem.ItemState ?? ExistingmateItem.ItemState;

            //The user has tamperded with his ad, so set it's approved property to false until it has been thorougly checked.
            ExistingmateItem.Approved = false;


            //////////////Now new photos----------Insert them--------//////////////////////////////
            var uploadsFolderPath = Path.Combine(_hostingEnv.WebRootPath, "Uploads");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }

            List <IFormFile> frmfiles = new List <IFormFile>();

            if (mateItem.FirstImage != null && mateItem.FirstImage.Length > 0 && mateItem.FirstImage.Length < Utilities.MAX_FILE_SIZE)
            {
                if (Utilities.ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(mateItem.FirstImage.FileName)))
                {
                    frmfiles.Add(mateItem.FirstImage);
                }
            }
            if (mateItem.SecondImage != null && mateItem.SecondImage.Length > 0 && mateItem.SecondImage.Length < Utilities.MAX_FILE_SIZE)
            {
                if (Utilities.ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(mateItem.SecondImage.FileName)))
                {
                    frmfiles.Add(mateItem.SecondImage);
                }
            }
            if (mateItem.ThirdImage != null && mateItem.ThirdImage.Length > 0 && mateItem.ThirdImage.Length < Utilities.MAX_FILE_SIZE)
            {
                if (Utilities.ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(mateItem.ThirdImage.FileName)))
                {
                    frmfiles.Add(mateItem.ThirdImage);
                }
            }

            if (frmfiles.Count > 0)
            {
                foreach (var item in frmfiles)
                {
                    var firstImgFileName = Guid.NewGuid().ToString() + Path.GetExtension(item.FileName);
                    var firstImgfilePath = Path.Combine(uploadsFolderPath, firstImgFileName);
                    //using (var stream = new FileStream(firstImgfilePath, FileMode.Create))
                    //{
                    //    item.CopyTo(stream);
                    //}

                    using (var img = Image.FromStream(item.OpenReadStream()))
                    {
                        Stream memStrm     = new MemoryStream(img.Resize(300, 200).ToByteArray());
                        var    filestrmRes = new FileStreamResult(memStrm, "image/jpg");
                        var    stream      = new FileStream(firstImgfilePath, FileMode.Create);
                        try
                        {
                            memStrm.CopyTo(stream);
                            //filestrmRes.FileStream.CopyTo(memStrm);
                        }
                        finally
                        {
                            stream.Dispose();
                        }
                    }

                    var newPhoto = new Photo
                    {
                        Filename = firstImgFileName
                    };

                    ExistingmateItem.ItemPhotos.Add(newPhoto);
                }
            }

            ///////////////////////////////////////////////////////////////////////////////////////

            _dbContext.Entry(ExistingmateItem).State = EntityState.Modified;
            _dbContext.SaveChanges();

            //Send email to the user and inform him that his ad has been disabled while update to his ad is beign inspected, and will be enabled if it passes necessary inspection. Also notify the admin to check and approve/dissaprove this post.
            NotifyAdminAndPostOwnerOfUpdatedPost(ExistingmateItem);

            return(Ok(ExistingmateItem));

            //string newUri = Url.Link("GetMateItem", new { id = ExistingmateItem.Id });
            //return Created(newUri, ExistingmateItem);
        }
Пример #12
0
        public IActionResult Post(MateItem mateItem)
        {
            MateItem newmateItem = mateItem;

            var     userClaims = User.Claims;
            var     UserId     = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault().Value;
            AppUser appUser    = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserId).FirstOrDefault();

            var uploadsFolderPath = Path.Combine(_hostingEnv.WebRootPath, "Uploads");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }

            //DONE: Find how to reduce file size(width & height), so that it will not have problem with xamarin Image control later.

            List <IFormFile> frmfiles = new List <IFormFile>();

            if (mateItem.FirstImage != null && mateItem.FirstImage.Length > 0 && mateItem.FirstImage.Length < Utilities.MAX_FILE_SIZE)
            {
                if (Utilities.ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(mateItem.FirstImage.FileName)))
                {
                    frmfiles.Add(mateItem.FirstImage);
                }
            }
            if (mateItem.SecondImage != null && mateItem.SecondImage.Length > 0 && mateItem.SecondImage.Length < Utilities.MAX_FILE_SIZE)
            {
                if (Utilities.ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(mateItem.SecondImage.FileName)))
                {
                    frmfiles.Add(mateItem.SecondImage);
                }
            }
            if (mateItem.ThirdImage != null && mateItem.ThirdImage.Length > 0 && mateItem.ThirdImage.Length < Utilities.MAX_FILE_SIZE)
            {
                if (Utilities.ACCEPTED_FILE_TYPES.Any(s => s == Path.GetExtension(mateItem.ThirdImage.FileName)))
                {
                    frmfiles.Add(mateItem.ThirdImage);
                }
            }

            if (frmfiles.Count > 0)
            {
                foreach (var item in frmfiles)
                {
                    var firstImgFileName = Guid.NewGuid().ToString() + Path.GetExtension(item.FileName);
                    var firstImgfilePath = Path.Combine(uploadsFolderPath, firstImgFileName);

                    using (var img = Image.FromStream(item.OpenReadStream()))
                    {
                        Stream memStrm     = new MemoryStream(img.Resize(300, 200).ToByteArray());
                        var    filestrmRes = new FileStreamResult(memStrm, "image/jpg");
                        var    stream      = new FileStream(firstImgfilePath, FileMode.Create);
                        try
                        {
                            memStrm.CopyTo(stream);
                            //filestrmRes.FileStream.CopyTo(memStrm);
                        }
                        finally
                        {
                            stream.Dispose();
                        }
                    }

                    var newPhoto = new Photo
                    {
                        Filename = firstImgFileName
                    };

                    newmateItem.ItemPhotos.Add(newPhoto);
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Submitted wrong data!"));
            }

            newmateItem.AppUserId = appUser.Id;
            //A bit redundant but the normal way is not working!!!
            newmateItem.Owner = _dbContext.AppUsers.Where(appusr => appusr.Id == newmateItem.AppUserId).FirstOrDefault();
            _dbContext.MateItems.Add(newmateItem);

            //appUser.Items.Add(newmateItem);
            _dbContext.SaveChanges();

            string newUri = Url.Link("GetMateItem", new { itemState = mateItem.ItemState, itemcategory = mateItem.ItemCategory, id = mateItem.Id });

            /////////////////////Now send mail to admin(Puppy), notifying him to go and approve the new post //////////////////////////
            NotifyAdminAndPostOwnerOfNewPost(newmateItem);
            ///////////////////End of send mail to admin(Puppy), notifying him to go and approve the new post///////////////////////

            return(Created(newUri, mateItem));
            //return Ok(mateItem);
        }
Пример #13
0
        public IActionResult GetItemByStateCategoryAndId(string itemState, string itemcategory, int id)
        {
            var currentUserDetails = new object();

            if (User.Identity.IsAuthenticated)
            {
                var userClaims   = User.Claims;
                var UserUniqueId = userClaims.Where(cl => cl.Type == "user_id").FirstOrDefault();

                currentUserDetails = new
                {
                    isUserAuth = User.Identity.IsAuthenticated,
                    uniqueId   = UserUniqueId.Value,
                    //Check whether the current user requesting this data is an admin, neat logic. Puppy stark!!!
                    isUserAdmin = _dbContext.AppUsers.Where(appusr => appusr.UniqueId == UserUniqueId.Value).FirstOrDefault().IsAdmin
                };
            }

            else
            {
                currentUserDetails = null;
            }

            //var isUserAuth = User.Identity.IsAuthenticated;

            MateItem mainMateItem = _dbContext.MateItems.Where(mi => mi.ItemState == itemState && mi.ItemCategory == itemcategory && mi.Id == id).FirstOrDefault();

            if (mainMateItem == null)
            {
                return(NotFound($"Could not found any item that matches your search"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Submitted wrong data!"));
            }

            //TDOD:Find a solution to this Owner always beig null and end the proccess of manually assigning owner to MateItem.
            mainMateItem.Owner = _dbContext.AppUsers.Where(appuser => appuser.Id == mainMateItem.AppUserId).FirstOrDefault();

            List <MateItem> otherMateItemsByOwner = _dbContext.MateItems.Where(mi => mi.AppUserId == mainMateItem.Owner.Id && mi.Id != mainMateItem.Id).ToList();

            ManuallyAssignOwnerToRelatedItems(mainMateItem, otherMateItemsByOwner);

            List <MateItem> otherMateItemsWithSameCatAndState = _dbContext.MateItems.Where(mi => mi.ItemCategory == mainMateItem.ItemCategory && mi.ItemState == mainMateItem.ItemState && mi.Id != mainMateItem.Id).ToList();

            ManuallyAssignOwnerToRelatedItems(mainMateItem, otherMateItemsWithSameCatAndState);

            mainMateItem.ViewCount++; //Increase the view count.
            _dbContext.SaveChanges(); //Save the increased number to database.

            var mateItemWithRelatedObjects = new
            {
                mainMateItem,
                otherMateItemsByOwner,
                otherMateItemsWithSameCatAndState,
                currentUserDetails
            };

            return(Ok(mateItemWithRelatedObjects));
        }