コード例 #1
0
        public async Task <VM_Agent> GetDetails(int id)
        {
            var agent = await _context.Agent.FindAsync(id);

            if (agent != null)
            {
                var posts = await _context.RealEstate
                            .Include(r => r.RealEstateDetail)
                            .Include(r => r.Map)
                            .Where(r => r.AgentId == agent.Id)
                            .ToListAsync();

                int total       = posts.Count;
                int activePosts = posts.Where(p => p.IsActive).ToList().Count;
                var details     = new VM_Agent()
                {
                    Id                = agent.Id,
                    Name              = agent.AgentName,
                    ContactNumber     = agent.PhoneNumber,
                    TotalPosts        = total,
                    ActivePosts       = activePosts,
                    IsActive          = agent.IsActive,
                    IsConfirmedNumber = agent.ConfirmPhoneNumber,
                    Posts             = posts
                };
                return(details);
            }
            return(null);
        }
コード例 #2
0
        public IActionResult UpdateProfile(VM_Agent updateProfile)
        {
            if (ModelState.IsValid)
            {
                var status = _services.UpdateProfile(updateProfile);

                return(Json(new { status }));
            }

            return(View(updateProfile));
        }
コード例 #3
0
        public bool UpdateProfile(VM_Agent updateProfile)
        {
            try
            {
                var agent = _context.Agent.Find(updateProfile.Id);

                if (agent != null)
                {
                    agent.AgentName   = updateProfile.Name;
                    agent.PhoneNumber = updateProfile.ContactNumber;
                    agent.Email       = updateProfile.Email;
                    _context.SaveChanges();

                    return(true);
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }