Пример #1
0
        public async Task <IActionResult> Profile(string id, bool readOnlyView = false)
        {
            ProfileViewModelVM      model = new ProfileViewModelVM();
            ApplicationUser1ModelVM user  = new ApplicationUser1ModelVM();

            try
            {
                if (readOnlyView != false)
                {
                    ViewBag.readOnlyView = true;
                }
                if (id != null)
                {
                    user.applicationUser = _context.Users.Where(u => u.Id == id).SingleOrDefault();
                    ViewBag.AdminEdit    = true;
                }
                else
                {
                    user.applicationUser = await _userManager.GetUserAsync(User);
                }
                if (user.applicationUser == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }
                else
                {
                    model = ProfileManager.Profile(_context, user, StatusMessage);
                    var roles = await _userManager.GetRolesAsync(user.applicationUser);

                    model.UserRole = roles[0];
                    if (model.UserRole == "Aggregator")
                    {
                        model.applicationUsers = await ShowAggregatorsFarmers();
                    }



                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                // Do something here
                return(View(model));
            }
        }
Пример #2
0
        public static ProfileViewModelVM Profile(ApplicationDbContext _context, ApplicationUser1ModelVM user, string StatusMessage)
        {
            var Model    = new ProfileViewModelVM();
            var mapCoord = "";
            var markers  = _context.Markers.Where(u => u.UserId == user.applicationUser.Id).SingleOrDefault();

            if (markers != null)
            {
                Model.Markers = markers.LatLng;
                mapCoord      = markers.LatLng;
            }
            else
            {
                Model.Markers = "Empty";
            }

            var model = new ProfileViewModel
            {
                FirstName = user.applicationUser.FirstName,
                LastName  = user.applicationUser.LastName,
                // Farmer_Id_Form_No = user.Farmer_Id_Form_No,
                Dob         = user.applicationUser.Dob,
                Username    = user.applicationUser.UserName,
                County      = user.applicationUser.County,
                SubCounty   = user.applicationUser.SubCounty,
                Ward        = user.applicationUser.Ward,
                PhoneNumber = user.applicationUser.PhoneNumber,
                Mpesa_No    = user.applicationUser.Mpesa_No,
                //  Gender = user.Gender,
                KraPin              = user.applicationUser.KraPin,
                Whatapp_No          = user.applicationUser.Whatapp_No,
                Bank_Info           = user.applicationUser.Bank_Info,
                Next_of_Kin         = user.applicationUser.Next_of_Kin,
                Next_of_Kin_Contact = user.applicationUser.Next_of_Kin_Contact,
                Acreage             = user.applicationUser.Acreage,
                Field_Coords        = mapCoord,
                Crop                        = user.applicationUser.Crop,
                Email                       = user.applicationUser.Email,
                IsEmailConfirmed            = user.applicationUser.EmailConfirmed,
                WalletAddress               = user.applicationUser.WalletAddress,
                StatusMessage               = StatusMessage,
                NationalIDNumber            = user.applicationUser.NationalIDNumber,
                SerialFormNumber            = user.applicationUser.SerialFormNumber,
                InputUsed                   = user.applicationUser.InputUsed,
                PlantingDate                = user.applicationUser.PlantingDate,
                Aggregator_Company          = user.applicationUser.Aggregator_Company,
                Company_Registration_Number = user.applicationUser.CompanyRegistrationNumber,
                Field_pin                   = user.applicationUser.Field_Pin,
                Economic_Activity           = user.applicationUser.Economic_Activity,
                Household_Size              = user.applicationUser.Household_Size,
                Disability_Type             = user.applicationUser.DisabilityType,
                Farmer_Id_Form_No           = user.applicationUser.Farmer_Id_Form_No,
                Input_Service               = user.applicationUser.InputService,
                supplier_Company            = user.applicationUser.supplier_Company,
                Planting_Season             = user.applicationUser.PlantingSeason
            };

            model.Yield_Quantity = Convert.ToInt32(user.applicationUser.YieldQuantity);

            Model.profileViewModel = model;

            return(Model);
        }