public async Task <ActionResult> Create(ContactCreateViewModel model)
        {
            if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0 && !validImageTypes.Contains(model.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string result = await UploadImage(model.ImageUpload);

            if (result != null)
            {
                model.Contact.ImageUrl = DreamFactoryContext.BaseAddress + "/files/" + result;
            }

            IEnumerable <Contact> records = new List <Contact> {
                model.Contact
            };

            records = (await databaseApi.CreateRecordsAsync("contact", records, new SqlQuery())).Records;

            IEnumerable <ContactContactGroup> relationshipRecords = new List <ContactContactGroup>
            {
                new ContactContactGroup
                {
                    ContactId      = records.Select(x => x.Id).FirstOrDefault(),
                    ContactGroupId = model.GroupId
                }
            };

            model.ContactInfoViewModel.ContactInfo.InfoType  = model.ContactInfoViewModel.InfoType.ToString();
            model.ContactInfoViewModel.ContactInfo.ContactId = records.Select(x => x.Id).FirstOrDefault();

            Task <DatabaseResourceWrapper <ContactContactGroup> > createRelationshipsTask = databaseApi.CreateRecordsAsync("contact_group_relationship", relationshipRecords, new SqlQuery());
            Task <DatabaseResourceWrapper <ContactInfo> >         createContactInfoTask   = databaseApi.CreateRecordsAsync("contact_info", new List <ContactInfo> {
                model.ContactInfoViewModel.ContactInfo
            }, new SqlQuery());

            await Task.WhenAll(createRelationshipsTask, createContactInfoTask);

            return(RedirectToAction("List", Request.QueryString.ToRouteValues(new { GroupId = model.GroupId })));
        }
Exemple #2
0
        public IActionResult Create([FromForm] ContactCreateViewModel contact)
        {
            if (TryValidateModel(contact))
            {
                _contactDatabase.Insert(new Contact
                {
                    Name       = contact.Name,
                    Surname    = contact.Surname,
                    Email      = contact.Email,
                    BirthDate  = contact.BirthDate,
                    TelNr      = contact.TelNr,
                    Address    = contact.Address,
                    Annotation = contact.Annotation
                });

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #3
0
        //PhonNumber(LIST)--> ContactCreateViewModel

        public static List <PhoneNumber> To_PhoneNumber_Create_ViewModel(this ContactCreateViewModel contactcreate, int val)
        {
            List <PhoneNumber>          listcontact       = new List <PhoneNumber>();
            List <PhoneNumberViewModel> mylistphonenumber = new List <PhoneNumberViewModel> {
                contactcreate.phonenumber1, contactcreate.phonenumber2, contactcreate.phonenumber3
            };

            foreach (PhoneNumberViewModel item in mylistphonenumber)
            {
                if (item != null && item.Number != null)
                {
                    PhoneNumber contact = new PhoneNumber()
                    {
                        Number        = item.Number,
                        ContactId     = val,
                        PhoneNumberId = item.PhoneNumberId
                    };
                    listcontact.Add(contact);
                }
            }
            return(listcontact);
        }
        //public AddContactResult Add(Contact contact)
        //{
        //    try
        //    {
        //        var existingContact = _ContactsRepository.GetAll().FirstOrDefault(x =>
        //                                            x.IsFullNameTrimmedEqual(contact.Firstname, contact.Lastname, contact.Middlename, contact.Suffix)
        //                                            ||
        //                                            x.Email.IsTrimmedEquals(contact.Email));

        //        if (existingContact != null)
        //        {
        //            return new AddContactResult()
        //            {
        //                Status = Dto.Enums.AddResultStatus.AlreadyExists,
        //                Entity = existingContact
        //            };
        //        }

        //        if (contact.AlbumImage != null)
        //        {
        //            var albumImage = new AlbumImage()
        //            {
        //                Filename = contact.AlbumImage.Filename,
        //                Filetype = contact.AlbumImage.Filetype,
        //                ImageBytes = contact.AlbumImage.ImageBytes
        //            };
        //            _AlbumImageRepository.Insert(albumImage);
        //            _AlbumImageRepository.SaveChanges();
        //            contact.AlbumImageId = albumImage.Id;
        //        }
        //        _ContactsRepository.Insert(contact);
        //        _ContactsRepository.SaveChanges();

        //        return new AddContactResult()
        //        {
        //            Status = Dto.Enums.AddResultStatus.Added,
        //            Entity = contact
        //        };
        //    }
        //    catch (Exception ex)
        //    {
        //        return new AddContactResult()
        //        {
        //            Status = Dto.Enums.AddResultStatus.Error,
        //            Entity = contact,
        //            Exception = ex
        //        };
        //    }
        //}

        public async Task <Contact> InsertContactAsync(ContactCreateViewModel model)
        {
            var ms = new MemoryStream();

            model.Photo.CopyTo(ms);
            var newContact = new Contact()
            {
                Firstname      = model.Firstname,
                Middlename     = model.Middlename,
                Lastname       = model.Lastname,
                DateOfBirth    = model.DateOfBirth,
                Email          = model.Email,
                HomePhone      = model.HomePhone,
                CellPhone      = model.CellPhone,
                Occupation     = model.Occupation,
                Suffix         = model.Suffix,
                ContactAddress = new ContactAddress()
                {
                    Address1  = model.Address1,
                    Address2  = model.Address2,
                    City      = model.City,
                    State     = model.State,
                    Zip       = model.Zip,
                    IsPrimary = true
                },
                AlbumImage = new AlbumImage()
                {
                    Filename   = model.Photo.FileName,
                    Filetype   = model.Photo.ContentType,
                    ImageBytes = ms.ToArray()
                }
            };

            _ContactsRepository.Insert(newContact);
            await _ContactsRepository.SaveChangesAsync();

            return(newContact);
        }
        public ActionResult Index(ContactCreateViewModel contact)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    Contact ct = new Contact();

                    ct.Name    = contact.Name;
                    ct.Email   = contact.Email;
                    ct.Phone   = contact.Phone;
                    ct.Content = contact.Content;

                    try
                    {
                        _contactService.Add(ct);

                        unitOfWork.Commit();

                        return(RedirectToAction("Ok"));
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);

                        ViewBag.Message = new GenericMessageViewModel
                        {
                            Message     = LocalizationService.GetResourceString("Contact.Error"),
                            MessageType = GenericMessages.warning
                        };
                    }
                }
            }
            return(View(contact));
        }
Exemple #6
0
        //ContactCreateViewModel--> PhonNumber(LIST)

        public static ContactCreateViewModel To_Contact_Create_ViewModel(this List <PhoneNumber> contactcreate)
        {
            ContactCreateViewModel      contactcreatevm = new ContactCreateViewModel();
            List <PhoneNumberViewModel> mynumberlist    = new List <PhoneNumberViewModel>();

            foreach (PhoneNumber item in contactcreate)
            {
                mynumberlist.Add(item.To_PhoneNumber_view_model());
            }

            if (mynumberlist.Count >= 1)
            {
                contactcreatevm.phonenumber1 = mynumberlist[0];
            }
            if (mynumberlist.Count >= 2)
            {
                contactcreatevm.phonenumber2 = mynumberlist[1];
            }
            if (mynumberlist.Count >= 3)
            {
                contactcreatevm.phonenumber3 = mynumberlist[2];
            }
            return(contactcreatevm);
        }
        public ActionResult Create(ContactCreateViewModel contactcreatevm, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                Contact _contact = ContactsMapper.To_Contact_Create_ViewModel(contactcreatevm);
                try
                {
                    if (file.ContentLength > 0)
                    {
                        string _FileName = Path.GetFileName(file.FileName);
                        string _path     = Path.Combine(Server.MapPath("~/UploadImg"), _FileName);
                        _contact.ImagePath = _FileName;
                        file.SaveAs(_path);
                    }
                }
                catch
                {
                    _contact.ImagePath = "images.png";
                }

                finally
                {
                    int val = 0;
                    _contactrepository.Create(_contact, ref val);
                    _contactrepository.Save();
                    List <PhoneNumber> _phonenumber = PhoneNumberMapper.To_PhoneNumber_Create_ViewModel(contactcreatevm, val).ToList();
                    foreach (PhoneNumber phonItem in _phonenumber)
                    {
                        _phonenumberrepository.Create(phonItem);
                        _phonenumberrepository.Save();
                    }
                }
                return(RedirectToAction("Contacts"));
            }
            return(View("Create"));
        }
        // GET: Contact
        public ActionResult Index()
        {
            ContactCreateViewModel contact = new ContactCreateViewModel();

            return(View(contact));
        }
Exemple #9
0
 public ContactCreate(string ownerId, ContactCreateViewModel vm)
 {
     ContactCreateViewModel = vm;
     OwnerId = ownerId;
 }
Exemple #10
0
        public IActionResult Create()
        {
            ContactCreateViewModel vm = new ContactCreateViewModel();

            return(View(vm));
        }