public ContactService(ContactServiceType type,
                       HandleType target,
                       string service,
                       object address)
 {
     Type             = type;
     TargetHandleType = target;
     Service          = service;
     Address          = address;
 }
 public ContactService(ContactServiceType type,
                        HandleType target,
                        string service,
                        object address)
 {
     Type = type;
     TargetHandleType = target;
     Service = service;
     Address = address;
 }
Exemplo n.º 3
0
        public ActionResult Edit(ContactViewModel contactViewModel, int[] SelectedServiceType)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (contactViewModel.SelectedEmail == true)
                    {
                        contactViewModel.NotificationType = 1;
                    }
                    if (contactViewModel.SelectedSms == true)
                    {
                        contactViewModel.NotificationType = 2;
                    }
                    if (contactViewModel.SelectedSms == true && contactViewModel.SelectedEmail == true)
                    {
                        contactViewModel.NotificationType = 3;
                    }


                    //Removes the selected customers ContactServices
                    db.ContactServiceTypes.RemoveRange(db.ContactServiceTypes.Where(x => x.ContactID == contactViewModel.ContactID));
                    if (SelectedServiceType != null)
                    {
                        //Add a new Set of ContactServices
                        foreach (var i in SelectedServiceType)
                        {
                            ContactServiceType cst = new ContactServiceType {
                                ContactID = contactViewModel.ContactID, ServiceTypeID = i
                            };
                            db.ContactServiceTypes.Add(cst);
                        }
                    }


                    Contact contact = new Contact
                    {
                        ContactID        = contactViewModel.ContactID,
                        FirstName        = contactViewModel.FirstName,
                        LastName         = contactViewModel.LastName,
                        Business         = contactViewModel.Business,
                        Email            = contactViewModel.Email,
                        Language         = contactViewModel.Language,
                        PhoneNumber      = contactViewModel.PhoneNumber,
                        NotificationType = contactViewModel.NotificationType,
                    };

                    db.Entry(contact).State = EntityState.Modified;
                    db.Entry(contact).Property(x => x.RegDate).IsModified     = false;
                    db.Entry(contact).Property(x => x.ContactGuid).IsModified = false;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }
            return(View(contactViewModel));
        }
Exemplo n.º 4
0
        public ActionResult Create(ContactViewModel contactViewModel, int[] SelectedServiceType)
        {
            try
            {
                if (!ModelState.IsValid || (db.Contacts.Any(x => x.Email == contactViewModel.Email)) || (db.Contacts.Any(x => x.PhoneNumber == contactViewModel.PhoneNumber)) || (contactViewModel.SelectedSms == false && contactViewModel.SelectedEmail == false)) //ha alla vilkor for icke-Godkänd
                {
                    contactViewModel.ServiceTypeList = db.ServiceTypes.ToList();
                    contactViewModel.SelectedSms     = contactViewModel.SelectedSms;
                    contactViewModel.SelectedEmail   = contactViewModel.SelectedEmail;

                    if (db.Contacts.Any(x => x.Email == contactViewModel.Email))
                    {
                        ModelState.AddModelError("Email", "Email already exists.");
                    }
                    if (db.Contacts.Any(x => x.PhoneNumber == contactViewModel.PhoneNumber))
                    {
                        ModelState.AddModelError("PhoneNumber", "PhoneNumber already exists.");
                    }
                    if (contactViewModel.SelectedSms == false && contactViewModel.SelectedEmail == false)
                    {
                        ViewBag.ErrorMessageNotificationType = "Atlest one Notificationtype must be selected.";
                    }
                    //If Something dosent validate, return error And selected values

                    if (SelectedServiceType != null)
                    {
                        contactViewModel.SelectedServiceTypeList = SelectedServiceType.ToList();
                    }

                    return(View(contactViewModel));
                }

                if (ModelState.IsValid)
                {
                    if (contactViewModel.SelectedEmail == true)
                    {
                        contactViewModel.NotificationType = 1;
                    }
                    if (contactViewModel.SelectedSms == true)
                    {
                        contactViewModel.NotificationType = 2;
                    }
                    if (contactViewModel.SelectedSms == true && contactViewModel.SelectedEmail == true)
                    {
                        contactViewModel.NotificationType = 3;
                    }

                    int ID;
                    if (db.Contacts.Count() != 0) //Gets and sets Contacts ID
                    {
                        ID = (from c in db.Contacts
                              select c.ContactID).Max() + 1;
                    }
                    else // Resets Contact identity
                    {
                        db.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Contacts', RESEED, 0)");
                        db.SaveChanges();
                        ID = 0;
                    }

                    if (SelectedServiceType != null)
                    {
                        foreach (var i in SelectedServiceType) //kolla om detta kan sparas i contact obj direkt
                        {
                            ContactServiceType contactServiceType = new ContactServiceType();
                            contactServiceType.ContactID     = ID;
                            contactServiceType.ServiceTypeID = i;
                            db.ContactServiceTypes.Add(contactServiceType);
                        }
                    }
                    Contact contact = new Contact
                    {
                        FirstName        = contactViewModel.FirstName,
                        LastName         = contactViewModel.LastName,
                        Business         = contactViewModel.Business,
                        Email            = contactViewModel.Email,
                        PhoneNumber      = contactViewModel.PhoneNumber,
                        NotificationType = contactViewModel.NotificationType,
                        ContactGuid      = Guid.NewGuid(),
                        RegDate          = DateTime.Now,
                        ContactID        = ID,
                        Language         = contactViewModel.Language,
                    };

                    db.Contacts.Add(contact);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                ModelState.AddModelError("", "Unable to save changes. Please try again, and if the problem persists, see your system administrator.");
                contactViewModel.ServiceTypeList = db.ServiceTypes.ToList();
                contactViewModel.SelectedSms     = contactViewModel.SelectedSms;
                contactViewModel.SelectedEmail   = contactViewModel.SelectedEmail;
                if (SelectedServiceType != null)
                {
                    contactViewModel.SelectedServiceTypeList = SelectedServiceType.ToList();
                }
            }
            return(View(contactViewModel));
        }
 public ContactService(ContactServiceType type,
                       HandleType target,
                       string service) : this(type, target, service, null)
 {
 }
 public ContactService(ContactServiceType type,
                        HandleType target,
                        string service)
     : this(type, target, service, null)
 {
 }