Beispiel #1
0
        public async Task <ActionResult> Create(int id, ProposalModels myProp)
        {
            var post = await _db.PostJobs.FirstOrDefaultAsync(p => p.Id == id);

            if (post == null)
            {
                return(HttpNotFound());
            }
            post.NumberOfSubmitted++;
            var userID = User.Identity.GetUserId();

            myProp.FreeLancerId = userID;
            myProp.PostId       = id;
            myProp.ClientId     = post.UserId;
            if (ModelState.IsValid)
            {
                bool existprop = await _db.Proposals.FirstOrDefaultAsync(p => p.PostId == id) != null;

                if (existprop)
                {
                    ViewBag.ExistProp = "You have already send a Proposal Before";
                }
                else
                {
                    _db.Proposals.Add(myProp);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("Index", "Posts", new { area = "" }));
                }
            }
            return(View());
        }
Beispiel #2
0
        public async Task <ActionResult> Edit(int id, ProposalModels proposal)
        {
            var propfromdb = await _db.Proposals.FirstOrDefaultAsync(p => p.IdOfProposal == id);

            var postid = propfromdb.PostId;

            if (propfromdb == null)
            {
                return(HttpNotFound());
            }
            if (ModelState.IsValid)
            {
                propfromdb.TheProposal = proposal.TheProposal;
                propfromdb.PostId      = postid;
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View());
        }