/// <summary>
        /// To the model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static ContactAddressModel ToModel(this ContactAddressViewModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new ContactAddressModel
            {
                ContactAddressID = model.ContactAddressID,
                ContactID        = model.ContactID,
                IsPrimary        = model.IsPrimary,
                AddressID        = model.AddressID,
                AddressTypeID    = model.AddressTypeID,
                Line1            = model.Line1,
                Line2            = model.Line2,
                City             = model.City,
                StateProvince    = model.StateProvince,
                County           = model.County,
                Zip              = model.Zip,
                ComplexName      = model.ComplexName,
                GateCode         = model.GateCode,
                ModifiedOn       = model.ModifiedOn,
                ExpirationDate   = model.ExpirationDate,
                EffectiveDate    = model.EffectiveDate,
                MailPermissionID = model.MailPermissionID
            };

            return(entity);
        }
Beispiel #2
0
        //[HttpPost]
        //public async Task<IActionResult> EditarFile(TeacherFileModel model, IFormFile file)
        //{
        //    var rutaPdf = _config.GetSection("rutas").GetSection("TeacherFiles").Value;
        //    //var file = model.FormFile;
        //    if (model.TeacherFileTypeId == null)
        //    {
        //        EnviarMensaje.Enviar(TempData, "red", "El tipo de archivo es requerido");


        //        return RedirectToAction("AgregarDocumento", new { id = model.TeacherId });
        //    }


        //    if (file != null)
        //    {
        //        //upload files to wwwroot
        //        //var fileName = Path.GetFileName(file.FileName);

        //        //judge if it is pdf file
        //        string ext = Path.GetExtension(file.FileName);
        //        var fileName = model.TeacherId + "-" + Guid.NewGuid() + ext;
        //        if (ext.ToLower() != ".pdf")
        //        {
        //            return RedirectToAction("AgregarDocumento", new { id = model.TeacherId });
        //        }
        //        var fileFullPath = Path.Combine(rutaPdf, fileName);
        //        //var filePath = "\\app-assets\\documentos\\teacher" + fileName;

        //        using (var fileSteam = new FileStream(fileFullPath, FileMode.Create))
        //        {
        //            await file.CopyToAsync(fileSteam);
        //        }
        //        //your logic to save filePath to database, for example


        //        model.File.FileName = file.FileName;
        //        model.File.FilePath = fileName;
        //        model.File.FileFullPath = fileFullPath;
        //        model.File.FileTypeId = model.TeacherFileTypeId;


        //        var data = CopyPropierties.Convert<TeacherFileModel, TeacherFile>(model);

        //        try
        //        {
        //            _teacherFile.Save(data);
        //        }
        //        catch (Exception e)
        //        {
        //            return RedirectToAction("AgregarDocumento", new { id = model.TeacherId });
        //        }
        //    }
        //    else
        //    {
        //        EnviarMensaje.Enviar(TempData, "red", "El archivo es requerido");

        //        return RedirectToAction("AgregarDocumento", new { id = model.TeacherId });

        //    }



        //    return RedirectToAction("AgregarDocumento", new { id = model.TeacherId });
        //}

        public IActionResult AgregarDireccion(int id)
        {
            var model       = new ContactAddressModel();
            var contactId   = _teacher.GetContactId(id);
            var teacherById = _teacher.GetById(id);

            model.ContactId          = contactId;
            model.TeacherId          = teacherById.TeacherId;
            model.TeacherFullName    = teacherById.Contact.ContactName + " " + teacherById.Contact.ContactLastname;
            model.ContactAddressList = _contactAddress.GetByContactId(contactId).ToList();

            ViewBag.Countries    = new SelectList(_country.GetAll, "CountryId", "CountryName");
            ViewBag.Cities       = new SelectList(_city.Cities, "CityId", "CityName");
            ViewBag.Province     = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
            ViewBag.AddressTypes = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
            return(View(model));
        }
Beispiel #3
0
        public IActionResult AgregarDireccion(ContactAddressModel model)
        {
            var data = CopyPropierties.Convert <ContactAddressModel, ContactAddress>(model);

            if (ModelState.IsValid)
            {
                try
                {
                    _contactAddress.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("AgregarDireccion", new { id = model.TeacherId }));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count() > 0).First();
                EnviarMensaje.Enviar(TempData, "red", errors.ErrorMessage);


                var contactId   = _teacher.GetContactId((int)model.TeacherId);
                var teacherById = _teacher.GetById((int)model.TeacherId);

                model.ContactId          = contactId;
                model.TeacherId          = teacherById.TeacherId;
                model.TeacherFullName    = teacherById.Contact.ContactName + " " + teacherById.Contact.ContactLastname;
                model.ContactAddressList = _contactAddress.GetByContactId(contactId).ToList();

                ViewBag.Countries    = new SelectList(_country.GetAll, "CountryId", "CountryName");
                ViewBag.Cities       = new SelectList(_city.Cities, "CityId", "CityName");
                ViewBag.Province     = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                ViewBag.AddressTypes = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");

                return(View(model));
            }


            return(RedirectToAction("AgregarDireccion", new { id = model.TeacherId }));
        }