Пример #1
0
        public async Task <IActionResult> Create([Bind("BranchId,Name,PhoneNumber,AddressNumStreet,TownCity")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(branch));
        }
        public async Task <IActionResult> Create([Bind("StatusId,Content")] OrderStatus orderStatus)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderStatus);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderStatus));
        }
        public async Task <IActionResult> Create([Bind("MealTypeId,MealTypeName,ShelfLocation")] MealType mealType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mealType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mealType));
        }
        public async Task <IActionResult> Create([Bind("ReferralReasonId,Content")] ReferralReason referralReason)
        {
            if (ModelState.IsValid)
            {
                _context.Add(referralReason);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(referralReason));
        }
        public async Task <IActionResult> Create([Bind("RoleId,RoleName")] VolunteerRole volunteerRole)
        {
            if (ModelState.IsValid)
            {
                _context.Add(volunteerRole);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(volunteerRole));
        }
        public async Task <IActionResult> Create([Bind("DietaryRequirementId,DietaryName,MatchedSetMeal,Description")] DietaryRequirement dietaryRequirement)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dietaryRequirement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dietaryRequirement));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("MealTypeId,InstockAmount")] MealInstock mealInstock)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mealInstock);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MealTypeId"] = new SelectList(_context.MealType, "MealTypeId", "MealTypeName", mealInstock.MealTypeId);
            return(View(mealInstock));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("VolunteerId,PoliceVetDate,PoliceVetVerified")] VolunteerPoliceInfo volunteerPoliceInfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(volunteerPoliceInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["VolunteerId"] = new SelectList(_context.Volunteer, "VolunteerId", "Address", volunteerPoliceInfo.VolunteerId);
            return(View(volunteerPoliceInfo));
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("VolunteerId,FirstName,LastName,PhoneNumber,Relationship")] VolunteerEmergencyContact volunteerEmergencyContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(volunteerEmergencyContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["VolunteerId"] = new SelectList(_context.Volunteer, "VolunteerId", "Address", volunteerEmergencyContact.VolunteerId);
            return(View(volunteerEmergencyContact));
        }
        public async Task <IActionResult> Create([Bind("ReferrerId,FirstName,LastName,OrganisationName,PhoneNumber,Email,TownCity,RoleId")] Referrer referrer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(referrer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoleId"] = new SelectList(_context.ReferrerRole, "RoleId", "RoleName", referrer.RoleId);
            return(View(referrer));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("VolunteerId,DeliveryTraining,HSTraining,FirstAidRaining,OtherTrainingSkill")] VolunteerTrainingInfo volunteerTrainingInfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(volunteerTrainingInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["VolunteerId"] = new SelectList(_context.Volunteer, "VolunteerId", "Address", volunteerTrainingInfo.VolunteerId);
            return(View(volunteerTrainingInfo));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("VolunteerId,FirstName,LastName,Dob,Email,PreferredPhone,AlternativePhone,Address,TownCity,PostCode,StatusId,BranchId,RoleId,IsAssignedUserAccount")] Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(volunteer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BranchId"] = new SelectList(_context.Branch, "BranchId", "Name", volunteer.BranchId);
            ViewData["RoleId"]   = new SelectList(_context.VolunteerRole, "RoleId", "RoleName", volunteer.RoleId);
            ViewData["StatusId"] = new SelectList(_context.VolunteerStatus, "StatusId", "Content", volunteer.StatusId);
            return(View(volunteer));
        }
        public async Task <IActionResult> Create([Bind("RecipientId,FirstName,LastName,AddressNumStreet,TownCity,Postcode,PhoneNumber,Email,DogOnProperty,BranchId,ReferralReasonId,OtherReferralInfo,AdultsNum,Under5ChildrenNum,_510ChildrenNum,_1117ChildrenNum,DietaryRequirementId,OtherAllergyInfo,AdditionalInfo,ReferrerId,CreatedDate")] Recipient recipient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipient);
                //var name = new SqlParameter("@RName", recipient.FirstName);
                //_context.Database.ExecuteSqlCommand("sp_Add_Recipient @RName", name);
                await _context.SaveChangesAsync();  //使用 Procedure 不用save

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BranchId"]             = new SelectList(_context.Branch, "BranchId", "Name", recipient.BranchId);
            ViewData["DietaryRequirementId"] = new SelectList(_context.DietaryRequirement, "DietaryRequirementId", "DietaryName", recipient.DietaryRequirementId);
            ViewData["ReferralReasonId"]     = new SelectList(_context.ReferralReason, "ReferralReasonId", "ReferralReasonId", recipient.ReferralReasonId);
            ViewData["ReferrerId"]           = new SelectList(_context.Referrer, "ReferrerId", "FirstName", recipient.ReferrerId);
            return(View(recipient));
        }
Пример #14
0
        public async Task <IActionResult> Create(BatchCreateViewModel batchCVM)
        {
            if (ModelState.IsValid)
            {
                _context.Add(new Batch
                {
                    // BatchId = batchCVM.BatchId,
                    MealTypeId = batchCVM.MealTypeId,
                    AddAmount  = batchCVM.AddAmount
                });
                await _context.SaveChangesAsync();

                ViewData["MealTypeId"] = new SelectList(_context.MealType, "MealTypeId", "MealTypeName");
                batchCVM.StatusMessage = string.Format("Batch Added! Amount: {0}", batchCVM.AddAmount);
                return(View(batchCVM));
            }
            ViewData["MealTypeId"] = new SelectList(_context.MealType, "MealTypeId", "MealTypeName", batchCVM.MealTypeId);
            return(View(batchCVM));
        }
        public async Task <IActionResult> EditUser(AppUserCreateViewModel appUserCreateViewModel)
        {
            if (ModelState.IsValid) //如果验证通过
            {                       //通过接收的AppUserVM的邮件找到AppUser
                var user = await _userManager.FindByEmailAsync(appUserCreateViewModel.Email);

                //如果找到User
                if (user != null)
                {
                    //============更新AppUser前  先判定志愿者的,并且取到,变更前和变更后的  VId=============
                    //如果传进来的AppUserVM的VId不为空:即用户设定了新的Volunteer
                    if (appUserCreateViewModel.VolunteerId != null)
                    {
                        //通过AppUserVM的VId,找到志愿者, 赋值给 currentVolunteer
                        var currentVolunteer = await _context.Volunteer.FindAsync(appUserCreateViewModel.VolunteerId);

                        //通过AppUserVM的VId,如果找到志愿者
                        if (currentVolunteer != null)
                        {   //看是否有前任:如果AppUser之前的Vid(该AppUser的前任Volunteer) 不为空,
                            if (user.VolunteerId != null)
                            {
                                //找到 前任,还原为 未分配。
                                var previousVolunteer = await _context.Volunteer.FindAsync(user.VolunteerId);

                                if (previousVolunteer != null && previousVolunteer.IsAssignedUserAccount == true)
                                {
                                    previousVolunteer.IsAssignedUserAccount = false;
                                }
                            }
                            //新任志愿者  标记为 已分配
                            currentVolunteer.IsAssignedUserAccount = true;
                            await _context.SaveChangesAsync();
                        }
                    }
                    else//如果传进来的AppUser 的Vid 为空: 即用户不打算分配任何志愿者
                    {
                        //看是否有前任:如果AppUser之前的Vid(该AppUser的前任Volunteer) 不为空,
                        if (user.VolunteerId != null)
                        {
                            //找到 前任,还原为 未分配。
                            var previousVolunteer = await _context.Volunteer.FindAsync(user.VolunteerId);

                            if (previousVolunteer != null && previousVolunteer.IsAssignedUserAccount == true)
                            {
                                previousVolunteer.IsAssignedUserAccount = false;
                            }
                        }
                    }
                    //============更新AppUser前  先判定志愿者的选择状态,并且取到,变更前和变更后的  VId=============



                    user.AppRoleId   = appUserCreateViewModel.AppUserRoleId;
                    user.VolunteerId = appUserCreateViewModel.VolunteerId;

                    try
                    {
                        await _userManager.UpdateAsync(user);

                        await _context.SaveChangesAsync();

                        var role = await _roleManager.FindByIdAsync(appUserCreateViewModel.AppUserRoleId.ToString());

                        if (role != null)
                        {
                            var resultAddToRole = await _userManager.AddToRoleAsync(user, role.Name);//Add AppUser to role table

                            if (resultAddToRole.Succeeded)
                            {
                                return(RedirectToAction("Index"));
                            }
                        }
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                    return(RedirectToAction("index"));
                }
            }//如果验证没通过 , 直接返回
            ViewData["Volunteers"]   = new SelectList(await _context.GetVolunteersForSelection(-1), "VId", "IdFullName", appUserCreateViewModel.VolunteerId);
            ViewData["AppUserRoles"] = new SelectList(await _roleManager.Roles.ToListAsync(), "Id", "Name", appUserCreateViewModel.AppUserRoleId);
            return(View(appUserCreateViewModel));
        }