public HttpResponseMessage GetPhoneBook(PhoneBookModel phoneBook) { var principal = Thread.CurrentPrincipal; List <PhoneBookResponseModel> lstGroups = new List <PhoneBookResponseModel>(); PhoneBookResponseModel group; if (principal.Identity.IsAuthenticated) { Common.User user = ((MyPrincipal)principal).UserDetails; DataTable dtGroups = Facade.PhoneBook.GetPhoneBookOfUser(user.UserGuid, phoneBook.PhoneBookGuid, string.Empty); foreach (DataRow row in dtGroups.Rows) { group = new PhoneBookResponseModel(); group.PhoneBookGuid = Helper.GetGuid(row["Guid"]); group.Name = row["Name"].ToString(); lstGroups.Add(group); } PhoneBookResponse response = new PhoneBookResponse(); response.IsSuccessful = true; response.PhoneBooks = lstGroups; return(Request.CreateResponse(HttpStatusCode.OK, response)); } else { return(Request.CreateResponse(HttpStatusCode.Accepted)); } }
public string AddUser(PbUser newPbUser) { try { using (var ctxModel = new PhoneBookModel()) { var existingUser = ctxModel.Users.FirstOrDefault(x => x.UserInternalId == newPbUser.UserInternalId); if (existingUser == null) { ctxModel.Users.Add(newPbUser); } else { if (existingUser.User != newPbUser.User) { existingUser.User = newPbUser.User; } } ctxModel.SaveChanges(); } return("Success"); } catch (Exception ex) { return(ex.Message); } }
public ActionResult Edit(int?id) { if (id == null) { return(NotFound()); } PhoneBookModel model = new PhoneBookModel(); if (id.HasValue && id != 0) { PhoneBook.Data.PhoneBook pbEntity = phoneBookService.GetPhoneBook(id.Value); if (pbEntity != null) { model.FirstName = pbEntity.FirstName; model.LastName = pbEntity.LastName; model.Email = pbEntity.Email; model.MobilePhone = pbEntity.MobilePhone; model.Organization = pbEntity.Organization; model.Phone = pbEntity.Phone; model.WorkPhone = pbEntity.WorkPhone; model.HomePhone = pbEntity.HomePhone; } else { return(NotFound()); } } return(View(model)); }
public static PhoneBook ToPhoneBookData(PhoneBookModel model) { return(new PhoneBook() { Name = model.Name }); }
public ActionResult Edit(int id, PhoneBookModel model) { if (id != model.Id) { return(NotFound()); } PhoneBook.Data.PhoneBook pbEntity = phoneBookService.GetPhoneBook(model.Id); if (ModelState.IsValid) { pbEntity.FirstName = model.FirstName; pbEntity.LastName = model.LastName; pbEntity.Email = model.Email; pbEntity.MobilePhone = model.MobilePhone; pbEntity.Organization = model.Organization; pbEntity.Phone = model.Phone; pbEntity.WorkPhone = model.WorkPhone; pbEntity.HomePhone = model.HomePhone; phoneBookService.UpdatePhoneBook(pbEntity); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <ActionResult> EditPhonebook(int id = 0) { PhoneBookModel model = new PhoneBookModel() { Entries = new List <EntryModel>() }; if (id == 0) { return(View(model)); } IRestResponse <PhoneBookModel> phonebookResponse = await RestHelper.Get <PhoneBookModel>($"{_apiUrl}/phonebook/getphonebookbyid", new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("id", id) }); if (phonebookResponse.IsSuccessful) { model = phonebookResponse.Data; IRestResponse <IEnumerable <EntryModel> > entiresResponse = await RestHelper.Get <IEnumerable <EntryModel> >($"{_apiUrl}/phonebook/GetPhoneBookEntriesForPhoneBook", new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("phoneId", id) }); if (entiresResponse.IsSuccessful) { model.Entries = entiresResponse.Data.ToList(); } } return(View(model)); }
private System.Data.DataTable GetData() { PhoneBookModel model = new PhoneBookModel(); var contacts = model.Contacts.Include(m => m.PhoneNumbers).ToList(); System.Data.DataTable dt = new System.Data.DataTable("TestTable"); dt.Columns.Add("Name"); dt.Columns.Add("National ID"); var count = 1; foreach (var item in contacts) { foreach (var i in item.PhoneNumbers) { if (item.PhoneNumbers.Count >= count) { dt.Columns.Add("Phone Numbers " + count++); } } dt.Rows.Add(item.Name, item.NationalId, string.Join(" , ", item.PhoneNumbers.Select(x => x.Number).ToList())); } return(dt); }
public string Put(PhoneBookModel model) { if (model != null && model.Id.HasValue) { //Test2 T_PHONE_BOOK item = service.GetById(model.Id.Value); if (item != null) { //Test4 --> Test2-->Test4 model.Fill(item); if (service.Put(item)) { return("Elementi u modifikua me sukses"); } else { return("Probleme gjate modifikimie"); } } else { return("Elementi nuk u gjet ne bazen e te dhenave"); } } else { return("Specifikoni nje objekt te vlefshem"); } }
public async Task <IHttpActionResult> SavePhonebook(PhoneBookModel model) { if (ModelState.IsValid) { if (model.Id > 0) { //save the changes to the data var existingModel = PhonebookUnitOfWork.PhonebookRepository.GetByID(model.Id); existingModel.Name = model.Name; PhonebookUnitOfWork.PhonebookRepository.Update(existingModel); } else { PhonebookUnitOfWork.PhonebookRepository.Insert(model.GetPhoneBookFrom()); } await PhonebookUnitOfWork.SaveAsync(); return(Ok(model)); } else { return(BadRequest(ModelState)); } }
public IActionResult Index(string searchString) { List <PhoneBookModel> model = new List <PhoneBookModel>(); phoneBookService.GetPhoneBooks().Where(x => x.UserId == _userManager.GetUserId(User)).ToList().ForEach(pb => { PhoneBookModel phoneBook = new PhoneBookModel { Id = pb.Id, FirstName = pb.FirstName, LastName = pb.LastName, Email = pb.Email, Phone = pb.Phone, Organization = pb.Organization, MobilePhone = pb.MobilePhone, HomePhone = pb.HomePhone, WorkPhone = pb.WorkPhone }; model.Add(phoneBook); }); if (!String.IsNullOrEmpty(searchString)) { model = model.Where(s => s.Phone.Contains(searchString)).ToList(); } return(View(model)); }
public string AddEntry(Entry newPbEntry) { try { using (var ctxModel = new PhoneBookModel()) { var existingEntry = ctxModel.Entries.FirstOrDefault( x => x.UserId == newPbEntry.UserId && x.Person == newPbEntry.Person); if (existingEntry == null) { ctxModel.Entries.Add(newPbEntry); } else { existingEntry.Number = newPbEntry.Number; } ctxModel.SaveChanges(); } return("Success"); } catch (Exception ex) { return(ex.Message); } }
public PhoneBookModel GetByID(long id) { PhoneBookModel model = new PhoneBookModel(); model.Preselect(service.GetById(id)); return(model); }
public static PhoneBook.Models.PhoneBook GetPhoneBookFrom(this PhoneBookModel phoneBookModel) { PhoneBook.Models.PhoneBook phoneBook = new PhoneBook.Models.PhoneBook(); phoneBook.Id = phoneBookModel.Id; phoneBook.Name = phoneBookModel.Name; return(phoneBook); }
public List <PbUser> GetUsers() { using (var ctxModel = new PhoneBookModel()) { var users = (from u in ctxModel.Users select u).ToList(); return(users.Count > 0 ? users : new List <PbUser>()); } }
public List <Contact> GetAll() { if (Contacts == null) { PhoneBookModel model = new PhoneBookModel(); return(model.Contacts.Include(m => m.PhoneNumbers).ToList()); } return(Contacts); }
public ActionResult Add(PhoneBookModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(_pbService.Add(model))); }
public int GetUserId(string userInternalId) { using (var ctxModel = new PhoneBookModel()) { var userId = (from u in ctxModel.Users where u.UserInternalId == userInternalId select u.Id).FirstOrDefault(); return(userId); } }
public List <Entry> GetEntries(int id) { using (var ctxModel = new PhoneBookModel()) { var entries = (from u in ctxModel.Entries where u.UserId == id select u).ToList(); return(entries.Count > 0 ? entries : new List <Entry>()); } }
public HttpResponseMessage GetPagedNumbers(PhoneBookModel phonebookInfo) { PostPhoneNumberModel phoneNumberModel; List <PostPhoneNumberModel> lstNumbers = new List <PostPhoneNumberModel>(); int resultCount = 0; var principal = Thread.CurrentPrincipal; if (!principal.Identity.IsAuthenticated) { throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.AccountIsInvalid, Language.GetString("AccountIsInvalid")); } if (phonebookInfo.PhoneBookGuid == Guid.Empty) { throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.BadRequest, Language.GetString("BadRequest")); } Common.User userInfo = ((MyPrincipal)principal).UserDetails; DataTable dtPhoneNumbers = Facade.PhoneNumber.GetPagedNumbers(phonebookInfo.PhoneBookGuid, string.Empty, "CreateDate", phonebookInfo.PageId, 100, ref resultCount); Parallel.ForEach <DataRow>(dtPhoneNumbers.AsEnumerable(), (row) => { phoneNumberModel = new PostPhoneNumberModel(); phoneNumberModel.FirstName = row["FirstName"].ToString(); phoneNumberModel.LastName = row["LastName"].ToString(); phoneNumberModel.BirthDate = Helper.GetDateTime(row["BirthDate"]); phoneNumberModel.Telephone = row["Telephone"].ToString(); phoneNumberModel.Mobile = row["CellPhone"].ToString(); phoneNumberModel.FaxNumber = row["FaxNumber"].ToString(); phoneNumberModel.Job = row["Job"].ToString(); phoneNumberModel.Address = row["Address"].ToString(); phoneNumberModel.ZipCode = row["ZipCode"].ToString(); phoneNumberModel.Email = row["Email"].ToString(); phoneNumberModel.Gender = Helper.GetInt(row["Sex"]); phoneNumberModel.ZoneGuid = Helper.GetGuid(row["ZoneGuid"]); lstNumbers.Add(phoneNumberModel); }); PhoneNumberResponse response = new PhoneNumberResponse(); response.IsSuccessful = true; response.TotalCount = resultCount; response.PhonebookGuid = phonebookInfo.PhoneBookGuid; response.Numbers = lstNumbers; return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public async Task <ActionResult> EditPhonebook(PhoneBookModel viewModel) { if (ModelState.IsValid) { IRestResponse <PhoneBookModel> phonebookModelResponse = await RestHelper.Save <PhoneBookModel>($"{_apiUrl}/phonebook/savephonebook", viewModel); if (phonebookModelResponse.IsSuccessful) { return(RedirectToAction("index")); } } return(View(viewModel)); }
public async Task <IActionResult> Add(PhoneBookModel model) { try { var response = await _phoneBookService.Add(model).ConfigureAwait(false); return(Ok(response)); } catch (Exception ex) { _logger.Error(ex); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
protected void Button1_Click(object sender, EventArgs e) { var model = new PhoneBookModel(); var contact = model.Contacts.FirstOrDefault(m => m.ContactId == Id); var num = Number1.Text; model.PhoneNumbers.Add(new PhoneNumber { ContactId = Id, Number = num.ToString(), Contact = contact }); model.SaveChanges(); Response.Redirect("Default.aspx"); }
protected void Button1_Click(object sender, EventArgs e) { string id = Request.QueryString["id"]; Id = int.Parse(id); var model = new PhoneBookModel(); var c = model.Contacts.FirstOrDefault(m => m.ContactId == Id); c.Name = Name1.Text; c.NationalId = NationalId1.Text; model.SaveChanges(); Response.Redirect("Default.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["PhoneId"])) { string id = Request.QueryString["PhoneId"]; var Id = int.Parse(id); var model = new PhoneBookModel(); var _phoneNumber = model.PhoneNumbers.FirstOrDefault(m => m.PhoneNumberID == Id); Number1.Text = _phoneNumber.Number; } } }
public bool AddContact(PhoneBookModel phoneBook) { try { _phoneBookComponent.AddContact(phoneBook); _logger.LogInformation($"Added phonebook entry - Name: {phoneBook.Name}"); return(true); } catch (Exception ex) { _logger.LogError(ex, "Error occurred on Index Controller"); return(false); } }
protected void Page_Load(object sender, EventArgs e) { var model = new PhoneBookModel(); if (!string.IsNullOrEmpty(Request.QueryString["searchword"])) { string searchword = Request.QueryString["searchword"]; Contacts = model.Contacts.Where(m => m.Name.ToLower().Contains(searchword.ToLower())).ToList(); GetAll(); } else { Contacts = model.Contacts.Include(m => m.PhoneNumbers).ToList(); GetAll(); } }
public ActionResult Details(int id) { PhoneBookModel model = new PhoneBookModel(); PhoneBook.Data.PhoneBook pbEntity = phoneBookService.GetPhoneBook(id); model.FirstName = pbEntity.FirstName; model.LastName = pbEntity.LastName; model.Email = pbEntity.Email; model.MobilePhone = pbEntity.MobilePhone; model.Organization = pbEntity.Organization; model.Phone = pbEntity.Phone; model.WorkPhone = pbEntity.WorkPhone; model.HomePhone = pbEntity.HomePhone; return(View(model)); }
//public string DeleteUser(string id) //{ // try // { // using (var ctxModel = new PhoneBookModel()) // { // ctxModel.Entries.RemoveRange(ctxModel.Entries.Where(e => e.Entry.UserId == id).ToList()); // ctxModel.Users.Remove(ctxModel.Users.Single(x=> x.PbUser.Id ==id)); // ctxModel.SaveChanges(); // return "Success"; // } // } // catch (Exception ex) // { // return ex.Message; // } //} public string DeleteEntry(int id) { try { using (var ctxModel = new PhoneBookModel()) { ctxModel.Entries.Remove(ctxModel.Entries.Single(e => e.Id == id)); ctxModel.SaveChanges(); return("Success"); } } catch (Exception ex) { return(ex.Message); } }
protected void Button1_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["PhoneId"])) { string id = Request.QueryString["PhoneId"]; var Id = int.Parse(id); var model = new PhoneBookModel(); var _phoneNumber = model.PhoneNumbers.FirstOrDefault(m => m.PhoneNumberID == Id); _phoneNumber.Number = Number1.Text; model.SaveChanges(); Response.Redirect("~/edit?id=" + _phoneNumber.ContactId); } }
public ActionResult Delete(int id) { PhoneBook.Data.PhoneBook pbEntity = phoneBookService.GetPhoneBook(id); PhoneBookModel model = new PhoneBookModel { FirstName = pbEntity.FirstName, LastName = pbEntity.LastName, Email = pbEntity.Email, MobilePhone = pbEntity.MobilePhone, Organization = pbEntity.Organization, Phone = pbEntity.Phone, WorkPhone = pbEntity.WorkPhone, HomePhone = pbEntity.HomePhone }; return(View(model)); }