Пример #1
0
 public ActionResult DeleteSave(string id)
 {
     phoneBookContext = new PhoneBookContext();
     phoneBookContext.Delete(Guid.Parse(id));
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
Пример #2
0
 public ActionResult UpdateSave(string id, string surname, string telephone)
 {
     phoneBookContext = new PhoneBookContext();
     phoneBookContext.Update(Guid.Parse(id), surname, telephone);
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
Пример #3
0
        public async Task <ResponseModel <IEnumerable <EntryOutputModel> > > GetByPhoneBookId(int phoneBookId)
        {
            try
            {
                using (var ctx = new PhoneBookContext())
                {
                    var entries = ctx.Entries.Where(x => x.PhoneBookId == phoneBookId);
                    if (entries.Count() == 0)
                    {
                        return(new ResponseModel <IEnumerable <EntryOutputModel> > {
                            ResponseMessage = Constants.RecordsNotFound, IsSuccessful = false
                        });
                    }

                    return(new ResponseModel <IEnumerable <EntryOutputModel> >
                    {
                        DataSet = entries.Select(_mapper.Map <EntryOutputModel>).OrderBy(w => w.Name).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ResponseModel <IEnumerable <EntryOutputModel> > {
                    ResponseMessage = Constants.UnexpectedError, IsSuccessful = false
                });
            }
        }
Пример #4
0
        public async Task <ResponseModel <IEnumerable <EntryOutputModel> > > Search(string searchString)
        {
            try
            {
                using (var ctx = new PhoneBookContext())
                {
                    var entries = ctx.Entries.Where(x => x.Name.ToLower().Contains(searchString) || x.PhoneNumber.ToLower().Contains(searchString));
                    if (entries.Count() == 0)
                    {
                        return(new ResponseModel <IEnumerable <EntryOutputModel> > {
                            ResponseMessage = Constants.RecordsNotFound, IsSuccessful = false
                        });
                    }

                    return(new ResponseModel <IEnumerable <EntryOutputModel> >
                    {
                        DataSet = entries.Select(_mapper.Map <EntryOutputModel>).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ResponseModel <IEnumerable <EntryOutputModel> > {
                    ResponseMessage = Constants.UnexpectedError, IsSuccessful = false
                });
            }
        }
Пример #5
0
 public Person GetById(int id)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         return(context.People.Find(id));
     }
 }
Пример #6
0
 public async Task <ResponseModel <EntryOutputModel> > Edit(int entryId, EntryInputModel entryModel)
 {
     try
     {
         using (var ctx = new PhoneBookContext())
         {
             var existinEntry = ctx.Entries.FirstOrDefault(x => x.EntryId == entryId);
             if (existinEntry.Name != existinEntry.Name || existinEntry.PhoneNumber != entryModel.PhoneNumber || existinEntry.PhoneBookId != entryModel.PhoneBookId)
             {
                 existinEntry.Name        = entryModel.Name;
                 existinEntry.PhoneNumber = entryModel.PhoneNumber;
                 existinEntry.PhoneBookId = entryModel.PhoneBookId;
                 await ctx.SaveChangesAsync();
             }
             return(new ResponseModel <EntryOutputModel> {
                 DataSet = _mapper.Map <Core.Entry, EntryOutputModel>(existinEntry)
             });
         }
     }
     catch (Exception ex)
     {
         return(new ResponseModel <EntryOutputModel> {
             ResponseMessage = Constants.UnexpectedError, IsSuccessful = false
         });
     }
 }
Пример #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public GetAllEmployeeResponse GetAllEmployee(GetAllEmployeeRequest request)
 {
     try
     {
         // trong Store em đang để so sánh với điều kiện @keyword = '' nên có đoạn gắn giá trị trống này cho tham số Keyword
         if (String.IsNullOrEmpty(request.Keyword))
         {
             request.Keyword = "";
         }
         DynamicParameters parameters = new DynamicParameters();
         parameters.Add("@keyword", request.Keyword);
         parameters.Add("@pageindex", request.PageIndex);
         parameters.Add("@pagesize", request.PageSize);
         using (var context = new PhoneBookContext())
         {
             List <ContactObject> result = context.Contacts.Select(c => new ContactObject {
                 ContactId = c.ContactId,
                 Email     = c.Email
             }).ToList();
             return(new GetAllEmployeeResponse
             {
                 Status = ResponseStatus.Susscess,
                 Contacts = result
             });
         }
     }
     catch (Exception ex)
     {
         return(new GetAllEmployeeResponse
         {
             Status = ResponseStatus.Fail,
             Message = ex.Message
         });
     }
 }
Пример #8
0
 public ActionResult AddSave(string surname, string telephone)
 {
     phoneBookContext = new PhoneBookContext();
     phoneBookContext.Add(surname, telephone);
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
Пример #9
0
 public ActionResult DeleteSave(string id)
 {
     phoneBookContext = new PhoneBookContext(Server.MapPath("~/Models/Data.json"));
     phoneBookContext.Delete(Guid.Parse(id));
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
Пример #10
0
        public Fixture()
        {
            var services = new ServiceCollection();

            // Initilized in memory database
            services
            .AddDbContext <PhoneBookContext>(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString()));

            // configurations of IMapper that map data transfer objects to domain models
            var mapper = new MapperConfiguration(cfg => {
                cfg.CreateMissingTypeMaps = true;
            }).CreateMapper();

            services.AddScoped(x => mapper);


            // register repositories
            services.AddScoped <ICompanyRepository, CompanyRepository>();
            services.AddScoped <IPersonRepository, PersonRepository>();

            // register services
            services.AddTransient <ICompanyService, CompanyService>();
            services.AddTransient <IPersonService, PersonService>();
            services.AddTransient <ICompanyPersonAggrigateService, CompanyPersonAggrigateService>();

            // string parsers
            services.RegisterStringParseFactory("PhoneBook.Infrastructure");
            services.AddTransient <IParser, CsvParser>();
            // IOC container
            ServiceProvider = services.BuildServiceProvider();
            Context         = ServiceProvider.GetService <PhoneBookContext>();
        }
Пример #11
0
 public ActionResult UpdateSave(string id, string surname, string telephone)
 {
     phoneBookContext = new PhoneBookContext(Server.MapPath("~/Models/Data.json"));
     phoneBookContext.Update(Guid.Parse(id), surname, telephone);
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
Пример #12
0
 public ActionResult Update(string idSelectedItem)
 {
     ViewBag.Id         = idSelectedItem;
     phoneBookContext   = new PhoneBookContext(Server.MapPath("~/Models/Data.json"));
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View());
 }
Пример #13
0
 public ActionResult AddSave(string surname, string telephone)
 {
     phoneBookContext = new PhoneBookContext(Server.MapPath("~/Models/Data.json"));
     phoneBookContext.Add(surname, telephone);
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View("Index"));
 }
Пример #14
0
 private Contact FindById(long id)
 {
     using (PhoneBookContext db = new PhoneBookContext())
     {
         return(db.Contacts.Find(id));
     }
 }
Пример #15
0
 public ResponseModel <PhoneBookOutputModel> GetById(int id)
 {
     try
     {
         using (var ctx = new PhoneBookContext())
         {
             var phoneBookModel = ctx.PhoneBooks.Include(c => c.Entries).FirstOrDefault(x => x.PhoneBookId == id);
             if (phoneBookModel == null)
             {
                 return(new ResponseModel <PhoneBookOutputModel> {
                     ResponseMessage = Constants.UnexpectedError, IsSuccessful = false
                 });
             }
             return(new ResponseModel <PhoneBookOutputModel> {
                 DataSet = _mapper.Map <Core.PhoneBook, PhoneBookOutputModel>(phoneBookModel)
             });
         }
     }
     catch (Exception ex)
     {
         return(new ResponseModel <PhoneBookOutputModel> {
             ResponseMessage = Constants.UnexpectedError, IsSuccessful = false
         });
     }
 }
Пример #16
0
 public ActionResult Update(string idSelectedItem)
 {
     ViewBag.Id         = idSelectedItem;
     phoneBookContext   = new PhoneBookContext();
     ViewBag.PhoneBooks = phoneBookContext.PhoneBooks;
     return(View());
 }
Пример #17
0
 public ContactDTO GetContactWithFeilds(int id)
 {
     try
     {
         using (var dbContext = new PhoneBookContext())
         {
             var contact       = dbContext.Contact.FirstOrDefault(f => f.Id == id);
             var contactfeilds = dbContext.ContactField.Where(w => w.ContactId == id);
             if (contact != null)
             {
                 return(new ContactDTO
                 {
                     Id = id,
                     Name = contact.Name,
                     ContactFields = contactfeilds.Select(s => new ContactFieldDTO
                     {
                         Id = s.Id,
                         ContactId = id,
                         Field = s.Field,
                         Value = s.Value
                     }).ToList()
                 });
             }
             else
             {
                 return(new ContactDTO());
             }
         }
     }
     catch (Exception ex)
     {
         return(new ContactDTO());
     }
 }
Пример #18
0
 public List <Person> GetAll()
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         return(context.People.ToList());
     }
 }
Пример #19
0
 public bool EditContact(ContactDTO model)
 {
     try
     {
         using (var dbContext = new PhoneBookContext())
         {
             var contact = new Contact();
             contact.Id   = model.Id;
             contact.Name = model.Name;
             foreach (var field in model.ContactFields)
             {
                 var cf = new ContactField();
                 cf.Id        = field.Id;
                 cf.Field     = field.Field;
                 cf.Value     = field.Value;
                 cf.ContactId = field.ContactId;
                 dbContext.ContactField.AddOrUpdate(cf);
             }
             dbContext.Contact.AddOrUpdate(contact);
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #20
0
 private List <Contact> ReadPhoneBook()
 {
     using (PhoneBookContext db = new PhoneBookContext())
     {
         List <Contact> contacts = db.Contacts.ToList();
         return(contacts.OrderBy(c => c.Name).ToList());
     }
 }
Пример #21
0
        public void DeleteUser()
        {
            PhoneBookContext _phoneBookContext = new PhoneBookContext();
            UserController   userController    = new UserController(_phoneBookContext);

            var result = userController.DeleteUser(5);

            Assert.IsNotNull(result);
        }
Пример #22
0
        public void GetUserList()
        {
            PhoneBookContext _phoneBookContext = new PhoneBookContext();
            UserController   userController    = new UserController(_phoneBookContext);
            var result = userController.GetUserList();

            Assert.IsTrue(result.Count > 0);
            Assert.IsNotNull(result);
        }
Пример #23
0
 }                                                     // Unit of work
 public TestBase(Fixture fixture)
 {
     Services = fixture.ServiceProvider;
     Context  = Services.GetService <PhoneBookContext>();
     if (Context.Database.EnsureCreated())
     {
         Context.SeedSampleData();
     }
 }
Пример #24
0
 public void Add(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var addedObject = context.Entry(person);
         addedObject.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Пример #25
0
        public void GetUserDetail()
        {
            PhoneBookContext _phoneBookContext = new PhoneBookContext();
            UserController   userController    = new UserController(_phoneBookContext);

            var result = userController.GetUserDetail(3);

            Assert.IsNotNull(result);
        }
Пример #26
0
 public void Delete(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var deletedObject = context.Entry(person);
         deletedObject.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Пример #27
0
        public User GetById(int id)
        {
            using (var context = new PhoneBookContext())
            {
                user = context.Users.Where(x => x.Id == id).FirstOrDefault();
            };

            return(user);
        }
Пример #28
0
        public User GetByUserNameAndPassword(string userName, string password)
        {
            using (var context = new PhoneBookContext())
            {
                user = context.Users.Where(x => x.UserName == userName && x.Password == password).FirstOrDefault();
            };

            return(user);
        }
        public void GetListTest()
        {
            PhoneBookContext _phonecontext    = new PhoneBookContext();
            ProducerConfig   _config          = new ProducerConfig();
            ValuesController valuesController = new ValuesController(_config, _phonecontext);
            var result = valuesController.GetList();

            Assert.IsTrue(result.Count > 0);
        }
Пример #30
0
 public void Update(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var updatedObject = context.Entry(person);
         updatedObject.State = EntityState.Modified;
         context.SaveChanges();
     }
 }