Ejemplo n.º 1
0
        public ActionResult Create(AddContactViewModel contact)  //([Bind(Include = "Email,FirstName,LastName,EventType,Avatar")] AddContactViewModel contact)
        {
            if (ModelState.IsValid)
            {
                Contact cnt = new Contact();
                if (contact.Avatar == null || !contact.Avatar.IsImage())
                {
                    cnt.Avatar = "";
                }
                else
                {
                    string path = Path.Combine(
                        HostingEnvironment.MapPath("~/Uploads"),
                        Path.GetFileName(contact.Avatar.FileName));
                    contact.Avatar.SaveAs(path);
                    cnt.Avatar = Path.Combine("~/Uploads", Path.GetFileName(contact.Avatar.FileName));
                }
                cnt.Email     = contact.Email;
                cnt.FirstName = contact.FirstName;
                cnt.LastName  = contact.LastName;
                cnt.EventType = contact.EventType;

                //db.Contacts.Add(contact);
                //db.SaveChanges();
                mHSTYDB.Add(cnt);
                mHSTYDB.Save();
                return(RedirectToAction("Index"));
            }

            ViewBag.Contacts = mHSTYDB.GetEntries();
            return(View(contact));
        }
Ejemplo n.º 2
0
 public AddContactPage()
 {
     InitializeComponent();
     _viewModel     = new AddContactViewModel();
     BindingContext = _viewModel;
     ProgenyCollectionView.ItemsSource = _viewModel.ProgenyCollection;
 }
Ejemplo n.º 3
0
        public ActionResult Add()
        {
            var contactTypes = _hermesDataContext.Parameters.SingleOrDefault(x => x.Name == "ContactType");

            if (contactTypes != null)
            {
                var splittedTypes   = contactTypes.Value.Split(',');
                var typesOfContacts = splittedTypes.Select(x => new SelectListItem
                {
                    Text  = x,
                    Value = x
                }).ToList();

                var viewModel = new AddContactViewModel
                {
                    ContactTypes      = typesOfContacts,
                    CreateDate        = DateTime.Now.Date,
                    ApplicationUser   = CurrentUser,
                    ApplicationUserId = CurrentUser.Id,
                    UniqueId          = Guid.NewGuid().ToString()
                };

                return(View(viewModel));
            }

            return(RedirectToAction("Error", "Home", new { msg = "Nie zdefiniowano typów kontaktów." }));
        }
Ejemplo n.º 4
0
        public async Task AddContactAsyncShouldWorkProperly()
        {
            //Arange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            //Act
            var db     = new ApplicationDbContext(options);
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ApplicationProfile>();
            });
            var mapper         = new Mapper(config);
            var contactService = new ContactService(db, mapper);

            var model = new AddContactViewModel
            {
                Email   = "*****@*****.**",
                Message = "Hello world!",
                Name    = "Niko",
                Subject = "Hi"
            };
            await contactService.AddContactAsync(model);

            //assert
            Assert.True(await db.Contacts.CountAsync() == 1);
        }
Ejemplo n.º 5
0
        public ActionResult AddContact(int id /*id of the account*/, FormCollection formValues)
        {
            int contactId = Int32.Parse(formValues["ContactId"]);

            //we retrieve the contact to add to the contact
            Contact contact = _contactService.GetContact(contactId);
            //we retrieve the account to add the contact to
            Account account = _accountService.GetAccount(id);

            account.Contacts.Add(contact);

            if (!_accountService.EditAccount(account))
            {
                //we redisplay the form in case something goes wrong
                string userName = this.User.Identity.Name;

                //we retrieve from the db the contacts of the user, that haven't been assigned to an account yet
                var contacts = _contactService.ListContactsByCriteria(c => (c.ResponsibleUser.UserName == userName) &&
                                                                      (c.Account == null));
                var viewModel = new AddContactViewModel
                {
                    AccountId = id,
                    Contacts  = new SelectList(contacts, "Id", "Email", 1)
                };

                return(View(viewModel));
            }

            return(View("Details", account));
        }
Ejemplo n.º 6
0
        public async Task AddContactAsync(AddContactViewModel addContactViewModel)
        {
            var contact = this.mapper.Map <Contact>(addContactViewModel);

            await this.db.Contacts.AddAsync(contact);

            await this.db.SaveChangesAsync();
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> AddContact(Guid tenderGuid)
        {
            int userOrganizationId = AccessManager.Value.UserOrganizationId;
            var contacts           = await ProfileProvider.Value.GetContacts(userOrganizationId, tenderGuid);

            var viewModel = new AddContactViewModel(tenderGuid, contacts.Select(m => new ContactViewModel(tenderGuid, m)));

            return(View(viewModel));
        }
Ejemplo n.º 8
0
        public AddContactView(ContactModel model = null, bool isFromMembership = false)
        {
            InitializeComponent();
            DataContext = ViewModel = new AddContactViewModel(model, isFromMembership);
            ViewModel.PropertyChanged += ViewModelOnPropertyChanged;

            Owner = Application.Current.MainWindow;

            Loaded += OnAddContactViewLoaded;
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Contact(AddContactViewModel addContactViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(addContactViewModel));
            }
            await this.contactService.AddContactAsync(addContactViewModel);

            this.TempData["Success"] = "Added Successfully!";
            return(this.View());
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> AddContact(AddContactViewModel addContact)
        {
            addContact.contact.userID = HttpContext.User.Identity.Name;
            if (ModelState.IsValid)
            {
                db.Contacts.Add(addContact.contact);
            }
            await db.SaveChangesAsync();

            return(RedirectToAction("AddContact"));
        }
Ejemplo n.º 11
0
 public IActionResult Post([FromBody] AddContactViewModel addContactViewModels)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _contactService.Add(addContactViewModels);
     _contactService.Save();
     return(Ok());
     //return Created("api/PhoneBook/"+addContactViewModels.Id, addContactViewModels);
 }
Ejemplo n.º 12
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            AddContactViewModel ViewModel = new AddContactViewModel()
            {
                UserId = user.Id
            };

            return(View(ViewModel));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> AddContact(AddContactViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            await DraftProvider.AddContact(viewModel.TenderGuid, viewModel.ContactId);

            return(RedirectToAction("Info", "DraftTenderInfo", new { tenderGuid = viewModel.TenderGuid }));
        }
Ejemplo n.º 14
0
        // adds your contact automaticly to some elses contact list in form of an adress generated by yourself
        public AddContact(User user)
        {
            this.InitializeComponent();
            var vm = new AddContactViewModel(user);

            vm.DisplayInvalidAdressPrompt += () => this.DisplayAlert("Error", "Invalid adress, try again", "OK");

            this.ReceiverAdress.Completed += (object sender, EventArgs e) =>
            {
                vm.SubmitCommand.Execute(null);
            };
            this.BindingContext = new AddContactViewModel(user);
        }
Ejemplo n.º 15
0
        public void Add(AddContactViewModel addContactViewModel)
        {
            var contact = new Contact()
            {
                FirstName    = addContactViewModel.FirstName,
                LastName     = addContactViewModel.LastName,
                MobileNumber = addContactViewModel.MobileNunmber,
                PhoneNumber  = addContactViewModel.PhoneNunmber,
                Address      = addContactViewModel.Address
            };

            _contactRepository.AddContact(contact);
        }
Ejemplo n.º 16
0
        public void Add(AddContactViewModel model)
        {
            var db      = new DataContext();
            var contact = new ContactModel()
            {
                CreateDate  = DateTime.Now,
                Email       = model.Email,
                Name        = model.Name,
                PhoneNumber = model.PhoneNumber,
            };

            db.Add <ContactModel>(contact);
            db.SaveChanges();
        }
Ejemplo n.º 17
0
        public IActionResult Contact(AddContactViewModel model)
        {
            _service.Add(model);

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("DefaultEndpointsProtocol=https;AccountName=warsztatycodeandcloud4;AccountKey=hklvuMnksQiAfviw90DxUo+QZw8NrUUrbJVi8bVZRVfWW4yQqKkXo8hEpGsfoMpzLNl59KPs8aAZrjFXz8QkOA==;EndpointSuffix=core.windows.net"));
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("myqueue");

            queue.CreateIfNotExistsAsync();



            return(View());
        }
Ejemplo n.º 18
0
        //
        // GET: /Account/AddTask

        public ActionResult AddContact(int id /*id of the account*/)
        {
            string userName = this.User.Identity.Name;

            //we retrieve from the db the contacts of the user, that haven't been assigned to an account yet
            var tasks = _contactService.ListContactsByCriteria(contact => (contact.ResponsibleUser.UserName == userName) &&
                                                               (contact.Account == null));
            var viewModel = new AddContactViewModel
            {
                AccountId = id,
                Contacts  = new SelectList(tasks, "Id", "Email", 1)
            };

            return(View(viewModel));
        }
Ejemplo n.º 19
0
 public ActionResult Add(AddContactViewModel model)
 {
     if (this.ModelState.IsValid)
     {
         Contact dbContact = new Contact
         {
             FirstName   = model.FirstName,
             LastName    = model.LastName,
             PhoneNumber = model.PhoneNumber,
             Description = model.Description
         };
         this.contacts.Add(dbContact);
         this.TempData["SuccessMsg"] = "Contact is added to the database!";
         return(this.RedirectToAction("Index", "Home"));
     }
     return(this.View(model));
 }
Ejemplo n.º 20
0
        // adds your contact automaticly to some elses contact list in form of an adress generated by yourself
        public AddContactPage()
        {
            this.InitializeComponent();

            var vm = new AddContactViewModel {
                Navigation = this.Navigation
            };

            vm.DisplayInvalidAdressPrompt += () => this.DisplayAlert("Error", "Invalid address, try again", "OK");
            vm.SuccessfulRequestPrompt    += () => this.DisplayAlert("Successful Request", "Your new contact needs to accept the request before you can start chatting!", "OK");

            this.ReceiverAdress.Completed += (object sender, EventArgs e) =>
            {
                vm.SubmitCommand.Execute(null);
            };
            this.BindingContext = vm;
        }
Ejemplo n.º 21
0
        public ContactsViewModel()
        {
            imageService  = ImageService.Instance;
            importService = ImportService.Instance;
            exportService = ExportService.Instance;

            AddContactViewModel       = new AddContactViewModel();
            AddContactViewModel.Save += AddContactViewModelOnSave;

            Contacts            = new ObservableRangeCollection <Contact>();
            ContactsView        = CollectionViewSource.GetDefaultView(Contacts);
            ContactsView.Filter = ContactsViewFilter;

            AddContactsListCommand = new RelayCommand(AddContactsList);
            DeleteContactCommand   = new RelayCommand(DeleteContact);
            ImportContactsCommand  = new RelayCommand(ImportContacts);
            ExportContactsCommand  = new RelayCommand(ExportContacts);
            ChooseImageCommand     = new RelayCommand(ChooseImage);
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> ContactAsync(AddContactViewModel model)
        {
            // Retrieve the storage account from the connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("DefaultEndpointsProtocol=https;AccountName=devcodeandcloud;AccountKey=9LhuuclWYiF5Oisb20idnhr8omIrghiGG8E4neyptO3MmXSRmjwVULkJslfzY4omSSdenU9ZS+0A8sv6XXsQtQ==;EndpointSuffix=core.windows.net"));


            // Create the queue client.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a queue.
            CloudQueue queue = queueClient.GetQueueReference("myqueue");

            // Create the queue if it doesn't already exist.
            await queue.CreateIfNotExistsAsync();

            // Create a message and add it to the queue.
            CloudQueueMessage message = new CloudQueueMessage(model.Email);
            await queue.AddMessageAsync(message);

            _service.AddAsync(model);
            return(View("Contact"));
        }
Ejemplo n.º 23
0
        public ActionResult Add(AddContactViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var domainModel = Mapper.Instance.Map <Contact>(model);

                    domainModel.CreateDate = domainModel.CreateDate.AddHours(int.Parse(model.CreateTime.Split(':')[0]));
                    domainModel.CreateDate = domainModel.CreateDate.AddMinutes(int.Parse(model.CreateTime.Split(':')[1]));

                    _hermesDataContext.Contacts.Add(domainModel);
                    _hermesDataContext.SaveChanges();

                    if (!string.IsNullOrEmpty(model.UniqueId))
                    {
                        var uploadFileDirectory = WebConfigurationManager.AppSettings["uploadDirectory"];
                        var baseDir             = Path.Combine(uploadFileDirectory, model.UniqueId);

                        if (Directory.Exists(baseDir))
                        {
                            foreach (var file in Directory.GetFiles(baseDir))
                            {
                                var binary = System.IO.File.ReadAllBytes(file);
                                var mime   = MimeMapping.GetMimeMapping(file);

                                var newAttachment = new Attachment()
                                {
                                    BinaryData = binary,
                                    ContactId  = domainModel.Id,
                                    CreateDate = DateTime.Now,
                                    MimeType   = mime,
                                    FileName   = Path.GetFileName(file)
                                };

                                _hermesDataContext.Attachments.Add(newAttachment);
                                System.IO.File.Delete(file);
                            }
                            _hermesDataContext.SaveChanges();
                        }
                    }

                    if (model.AddTaskAfterContact)
                    {
                        var client  = _optimaDbContext.Kontrahenci.Find(domainModel.KntId);
                        var newTask = new TaskItem()
                        {
                            ItemStatus   = TaskItemStatus.InProgress,
                            GroupId      = CurrentUser.UserGroups.FirstOrDefault(x => x.Group.IsActive)?.GroupId,
                            CreateDate   = domainModel.CreateDate,
                            Title        = $"Przypomnienie odnośnie kontaktu z {client.Knt_Nazwa1}",
                            Note         = domainModel.Note,
                            CreatedById  = CurrentUser.Id,
                            DeadlineDate = domainModel.CreateDate.AddDays(7)
                        };

                        _hermesDataContext.TaskItems.Add(newTask);
                        _hermesDataContext.SaveChanges();
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Note", e.Message);
                }
            }

            if (!string.IsNullOrEmpty(model.UniqueId))
            {
                model.Attachments = GetExistingAttachments(model.UniqueId);
            }

            var contactTypes    = _hermesDataContext.Parameters.SingleOrDefault(x => x.Name == "ContactType");
            var splittedTypes   = contactTypes.Value.Split(',');
            var typesOfContacts = splittedTypes.Select(x => new SelectListItem
            {
                Text  = x,
                Value = x
            }).ToList();

            model.ContactTypes      = typesOfContacts;
            model.ApplicationUser   = CurrentUser;
            model.ApplicationUserId = CurrentUser.Id;
            return(View(model));
        }
Ejemplo n.º 24
0
 public MainPage()
 {
     InitializeComponent();
     BindingContext        = new AddContactViewModel();
     mPicker.SelectedIndex = 0;
 }
Ejemplo n.º 25
0
 private void AddContactViewModelOnSave(object sender, EventArgs args)
 {
     Contacts.Add(AddContactViewModel.Contact);
     AddContactViewModel.Reset();
 }
Ejemplo n.º 26
0
 public IActionResult Contact(AddContactViewModel model)
 {
     _service.Add(model);
     return(View());
 }
Ejemplo n.º 27
0
 public AddContactWindow()
 {
     InitializeComponent();
     DataContext = new AddContactViewModel();
 }
Ejemplo n.º 28
0
 public void Add(AddContactViewModel model)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
        public ActionResult ConvertMsgToContact(IEnumerable <HttpPostedFileBase> files)
        {
            try
            {
                var emailMessage = new MsgReader.Outlook.Storage.Message(files.First().InputStream);
                var clientEmail  = emailMessage.Recipients.FirstOrDefault().Email;
                var clientFromDb =
                    _optimaDbContext.Kontrahenci.FirstOrDefault(x => x.Knt_Email.StartsWith(clientEmail));

                if (!emailMessage.SentOn.HasValue)
                {
                    return(Json($"E-mail nie został wysłany do odbiorcy."));
                }

                var guid = Guid.NewGuid().ToString();

                if (emailMessage.Attachments != null && emailMessage.Attachments.Any())
                {
                    var uploadFileDirectory = WebConfigurationManager.AppSettings["uploadDirectory"];
                    var baseDir             = Path.Combine(uploadFileDirectory, guid);
                    if (!Directory.Exists(baseDir))
                    {
                        Directory.CreateDirectory(baseDir);
                    }

                    foreach (MsgReader.Outlook.Storage.Attachment file in emailMessage.Attachments)
                    {
                        string filePath = Path.Combine(baseDir, file.FileName);
                        if (!System.IO.File.Exists(filePath))
                        {
                            System.IO.File.WriteAllBytes(filePath, file.Data);
                        }
                    }
                }

                var newContactFromEmail = new AddContactViewModel()
                {
                    ApplicationUser     = CurrentUser,
                    ApplicationUserId   = CurrentUser.Id,
                    CreateDate          = emailMessage.SentOn.Value,
                    CreateTime          = emailMessage.SentOn.Value.ToShortTimeString(),
                    SelectedContactType = "Email",
                    Note          = emailMessage.BodyText,
                    ClientDisplay = clientFromDb?.Knt_Nazwa1,
                    KntId         = clientFromDb?.Knt_KntId ?? default(int),
                    IsImported    = true,
                    UniqueId      = guid
                };

                newContactFromEmail.Attachments = GetExistingAttachments(newContactFromEmail.UniqueId);

                var result = new ImportEmailResult
                {
                    FormData    = this.RenderRazorViewToString("Partial/_AddContactFormData", newContactFromEmail),
                    Attachments =
                        this.RenderRazorViewToString("Partial/_AttachmentListPartial", newContactFromEmail.Attachments)
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json("Błąd podczas konwertowania pliku"));
            }
        }
Ejemplo n.º 30
0
        public AddContactPage(IChatController controller)
        {
            InitializeComponent();

            BindingContext = new AddContactViewModel(controller);
        }