Inheritance: System.Web.UI.Page
Esempio n. 1
0
        public bool UpdateContact(ContactEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var contactId = model.ContactId;
                var entity    = GetContactFromDatabase(ctx, contactId);
                //var contactInterests = new InterestService().GetContactInterests(contactId);

                if (entity == null)
                {
                    return(false);
                }

                entity.FirstName   = model.FirstName;
                entity.LastName    = model.LastName;
                entity.Nickname    = model.Nickname;
                entity.Address     = model.Address;
                entity.PhoneNumber = model.PhoneNumber;
                entity.Birthday    = model.Birthday;
                entity.Notes       = model.Notes;
                entity.HasTalked   = model.HasTalked;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 2
0
        //GET: Contact/Edit/id
        public ActionResult Edit(int id)
        {
            var svc    = CreateContactService();
            var detail = svc.GetContactByPersonnelId(id);
            var model  =
                new ContactEdit
            {
                Id                = detail.Id,
                PersonnelId       = detail.PersonnelId,
                Personnel         = detail.Personnel,
                PhoneNumber       = detail.PhoneNumber,
                PersonalEmail     = detail.PersonalEmail,
                MilEmail          = detail.MilEmail,
                HasDriversLicense = detail.HasDriversLicense,
                VehicleMake       = detail.VehicleMake,
                VehicleModel      = detail.VehicleModel,
                VehicleColor      = detail.VehicleColor,
                VehiclePlate      = detail.VehiclePlate,
                VehicleYear       = detail.VehicleYear,
                VehicleInspected  = detail.VehicleInspected,
                //CreatedBy = detail.CreatedBy,
                //CreatedUtc = detail.CreatedUtc,
                ModifiedLast = detail.ModifiedLast,
                ModifiedUtc  = detail.ModifiedUtc
            };

            return(View(model));
        }
 public bool UpdateContact(ContactEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var user     = ctx.Users.Find(_userId.ToString());
         var userName = user.UserName;
         var entity   =
             ctx
             .ContactDbSet
             .Single(e => e.ContactId == model.Id);
         entity.PersonnelId        = model.PersonnelId;
         entity.Personnel          = model.Personnel;
         entity.PhoneNumber        = model.PhoneNumber;
         entity.PersonalEmail      = model.PersonalEmail;
         entity.MilEmail           = model.MilEmail;
         entity.HasDriversLicense  = model.HasDriversLicense;
         entity.VehicleMake        = model.VehicleMake;
         entity.VehicleModel       = model.VehicleModel;
         entity.VehicleColor       = model.VehicleColor;
         entity.VehicleYear        = model.VehicleYear;
         entity.VehicleInspected   = model.VehicleInspected;
         entity.ModifiedByUserName = userName;
         entity.ModifiedLast       = _userId;
         entity.ModifiedUtc        = DateTimeOffset.Now;
         return(ctx.SaveChanges() == 1);
     }
 }
Esempio n. 4
0
        public ActionResult Edit(int id)
        {
            var service = CreateContactService();
            var contact = service.GetContactById(id);

            var model =
                new ContactEdit
            {
                ContactId   = contact.ContactId,
                FirstName   = contact.FirstName,
                LastName    = contact.LastName,
                Nickname    = contact.Nickname,
                Address     = contact.Address,
                PhoneNumber = contact.PhoneNumber,
                Birthday    = contact.Birthday,
                Notes       = contact.Notes,
            };

            //PopulateContactInterestData();
            if (contact == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Esempio n. 5
0
        public override bool Update()
        {
            ContactEdit windowEdit = new ContactEdit(this);

            windowEdit.ShowDialog();

            if (windowEdit.DialogResult.HasValue && windowEdit.DialogResult.Value == true)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        public IHttpActionResult Put(ContactEdit contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateContactService();

            if (!service.UpdateContact(contact))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Esempio n. 7
0
        private bool SetStarState(int contactId, bool newState)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new ContactService(userId);

            var detail = service.GetContactById(contactId);

            var updatedContact =
                new ContactEdit
            {
                ContactId = detail.ContactId,

                HasTalked = newState
            };

            return(service.UpdateContact(updatedContact));
        }
Esempio n. 8
0
        public ActionResult Edit(ContactEdit contact)
        {
            if (!Contacts.Exists(contact.Name))
            {
                return(NotFound($"Contact with '{contact.Name}' was not found"));
            }
            if (Contacts.Exists(contact.NewName))
            {
                return(Conflict($"Contact with '{contact.NewName}' was found"));
            }

            Contacts.Delete(contact.Name);

            return(Add(new Contact {
                Email = contact.Email, Name = contact.NewName, Phone = contact.Phone
            }));
        }
Esempio n. 9
0
        public ActionResult Edit(int id, ContactEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.Id != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var svc = CreateContactService();

            if (svc.UpdateContact(model))
            {
                TempData["SaveResult"] = "Record updated.";
                return(RedirectToAction("Details", new { id = model.PersonnelId }));
            }
            ModelState.AddModelError("", "Unable to update record.");
            return(View());
        }
Esempio n. 10
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var user = await _userManager.GetUserAsync(User);

            ContactLink cl = await _context.contactLinks.FirstOrDefaultAsync(m => m.Id == id);

            if (cl == null)
            {
                return(NotFound());
            }
            if (ce == null)
            {
                ce = new ContactEdit();
            }
            ce.Id         = cl.Id;
            ce.ParentName = await _userManager.GetUserNameAsync(user);

            ce.Creation       = cl.Creation;
            ce.FamilyName     = cl.FamilyName;
            ce.GivenNames     = cl.GivenNames;
            ce.LastUsed       = cl.LastUsed;
            ce.Expires        = cl.Expires;
            ce.Phones         = cl.Phones;
            ce.AlternateEmail = cl.AlternateEmail;
            ce.Relationship   = cl.Relationship;
            ce.RelType        = cl.Type;
            ce.ChildEmail     = "email not found";
            UserObject child = await _userManager.FindByIdAsync(cl.Child);

            if (child != null)
            {
                ce.ChildEmail = child.Email;
            }

            return(Page());
        }
Esempio n. 11
0
        public ActionResult Edit(int?id, ContactEdit model, string[] chosenInterests)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ContactId != id)
            {
                ModelState.AddModelError("", "Error");
                return(View(model));
            }

            var service = CreateContactService();

            if (service.UpdateContact(model))
            {
                TempData["SaveResult"] = "Contact updated";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Could not be updated.");
            return(View(model));
        }