public ActionResult Upload(HttpPostedFileBase file)
 {
     using (var package = new ExcelPackage(file.InputStream))
     {
         var workSheet = package.Workbook.Worksheets.First();
         var noOfCol   = workSheet.Dimension.End.Column;
         var noOfRow   = workSheet.Dimension.End.Row;
         if (noOfCol != 4)
         {
             ModelState.AddModelError(nameof(file), "Invalid file");
             return(View());
         }
         for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
         {
             var ecnumber   = workSheet.Cells[rowIterator, 1].Text;
             var fname      = workSheet.Cells[rowIterator, 2].Text;
             var lastmane   = workSheet.Cells[rowIterator, 3].Text;
             var nationalid = workSheet.Cells[rowIterator, 4].Text;
             var officer    = new ExtensionOfficer
             {
                 ECNumber     = ecnumber,
                 Firstname    = fname,
                 Surname      = lastmane,
                 CreationDate = DateTime.UtcNow,
                 NationalID   = nationalid,
                 ID           = Guid.NewGuid(),
             };
             DB.ExtensionOfficers.Add(officer);
         }
     }
     DB.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
 public ActionResult Add(ExtensionOfficer officer)
 {
     officer.CreationDate = DateTime.UtcNow;
     officer.ID           = Guid.NewGuid();
     DB.ExtensionOfficers.Add(officer);
     DB.SaveChanges();
     return(RedirectToAction(nameof(Details), new { officer.ID }));
 }
Beispiel #3
0
        protected override void OnResume()
        {
            base.OnResume();
            var oficer = ExtensionOfficer.DB.Rows.FirstOrDefault();

            if (oficer != null)
            {
                CurMember = oficer;
                LoadMember();
                ExtensionOfficer.DB.Truncate();
            }
        }
Beispiel #4
0
        async void LoadMember()
        {
            CurMember = await ExtensionOfficer.DB.RowsAsync.FirstOrDefaultAsync();

            TextECnumber.Text    = CurMember.ECNumber;
            TextNationalID.Text  = CurMember.NationalID;
            TextFirstName.Text   = CurMember.Firstname;
            TextLastName.Text    = CurMember.Surname;
            TextMobile.Text      = CurMember.Mobile;
            TextEmail.Text       = CurMember.Email;
            TextProvince.Text    = CurMember.Province;
            TextDistrict.Text    = CurMember.District;
            TextDateOfBirth.Text = CurMember.DateOfBirth?.ToString("dd-MMM-yyy");
            SpinnerGender.SetSelection(CurMember.GenderID ?? 1);
            DOB = CurMember.DateOfBirth;
        }