Exemple #1
0
 public async Task <IActionResult> AddGroupAsync([FromBody] AddHostelAc addHostelAc)
 {
     if (string.IsNullOrEmpty(addHostelAc.Name.Trim()))
     {
         return(Ok(new SharedLookUpResponse()
         {
             HasError = true,
             ErrorType = SharedLookUpResponseType.Name,
             Message = "Hostel name can't be null or empty"
         }));
     }
     else if (string.IsNullOrEmpty(addHostelAc.Code.Trim()))
     {
         return(Ok(new SharedLookUpResponse()
         {
             HasError = true,
             ErrorType = SharedLookUpResponseType.Name,
             Message = "Hostel code can't be null or empty"
         }));
     }
     else
     {
         return(Ok(await hostelManagementRepository.AddHostelAsync(addHostelAc, await GetUserCurrentSelectedInstituteIdAsync())));
     }
 }
Exemple #2
0
        public async Task <SharedLookUpResponse> AddHostelAsync(AddHostelAc addHostel, int instituteId)
        {
            if (!await iMSDbContext.Hostels.AnyAsync(x => x.InstituteId == instituteId && x.Code.ToLowerInvariant() == addHostel.Code.ToLowerInvariant() && x.Name.ToLowerInvariant() == addHostel.Name.ToLowerInvariant()))
            {
                var hostel = new IMS.DomainModel.Models.Hostel()
                {
                    CreatedOn            = DateTime.UtcNow,
                    InstituteId          = instituteId,
                    Name                 = addHostel.Name,
                    Code                 = addHostel.Code,
                    HostelType           = addHostel.HostelType,
                    HostelCautionDeposit = addHostel.HostelCautionDeposit,
                    ContactMobile        = addHostel.ContactMobile,
                    ContactPerson        = addHostel.ContactPerson,
                    CountryId            = addHostel.CountryId,
                    StateId              = addHostel.StateId,
                    CityId               = addHostel.CityId,
                    ZipCode              = addHostel.ZipCode,
                    Address1             = addHostel.Address1,
                    Address2             = addHostel.Address2,
                    PlaceName            = addHostel.PlaceName,
                    Status               = addHostel.Status
                };
                var insertObject = iMSDbContext.Hostels.Add(hostel);
                foreach (var studentId in addHostel.AssignMembers)
                {
                    var assignMember = new HostelStudentAssign()
                    {
                        StudentId = studentId,
                        HostelId  = insertObject.Entity.Id
                    };
                    iMSDbContext.HostelStudentAssign.Add(assignMember);
                }
                await iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Hostel added successfully"
                });
            }
            else
            {
                return(new SharedLookUpResponse()
                {
                    HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Hostel with same code is already existed"
                });
            }
        }