Ignore:
Timestamp:
08/23/24 15:40:14 (2 months ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
e9bb9d1
Parents:
72b1da2
Message:

fix access

implement multiple access pages with different roles
optimize present three structure of BlogPost and Answer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/BlogPostAnswersController.cs

    r72b1da2 r118e414  
    5858        [HttpPost]
    5959        [ValidateAntiForgeryToken]
    60         public ActionResult Create([Bind(include: "id,parent_id,reply,root_post,usersID")] BlogPostAnswers answerClass)
     60        public async Task<ActionResult> CreateAsync(int? id, int? parentId, [Bind(include: "reply")] BlogPostAnswers answerClass)
    6161        {
    62             if (ModelState.IsValid)
     62
     63            //string id = Request.Query["BlogId"];
     64            if (id == null && id > 0)
    6365            {
     66                return RedirectToAction("NotExist", "Error");
     67            }
     68            //string id = Request.Query["BlogId"];
     69            if (parentId== null && parentId > 0)
     70            {
     71                return RedirectToAction("NotExist", "Error");
     72            }
     73            if (answerClass != null && answerClass.reply.Length > 0)
     74            {
     75
     76                var user = await _userManager.GetUserAsync(User);
     77                if (user == null)
     78                {
     79                    return RedirectToAction("AccessDenied", "Error");
     80                }
     81
     82
     83                var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);
     84                answerClass.usersid = customerClass.id;
     85                answerClass.BlogPostConsultationid = (int)id;
     86                answerClass.parent_id = (int)parentId;
    6487                db.BlogPostAnswersObj.Add(answerClass);
    6588                db.SaveChanges();
    66                 return RedirectToAction("Index");
     89                //return RedirectToAction("Index");
     90                return RedirectToAction("Details", "Blog", new { id });
    6791            }
    6892
Note: See TracChangeset for help on using the changeset viewer.