コード例 #1
0
        public PhoneTypeModel GetById(int id)
        {
            phoneType      entity = this._repository.GetById(id);
            PhoneTypeModel model  = this.ConvertEntityToModel(entity);

            return(model);
        }
コード例 #2
0
        // POST: api/LookupType
        public HttpResponseMessage Post([FromBody] PhoneTypeModel phoneType)
        {
            int phoneTypeId = _phoneTypeServices.Create(phoneType);

            return(phoneTypeId > 0
                ? Request.CreateResponse(HttpStatusCode.OK, phoneTypeId)
                : Request.CreateResponse(HttpStatusCode.Conflict, "Phone Type with this name exists."));
        }
コード例 #3
0
        static void Main(string[] args)
        {
            AddressTypeModel newAddressTypeModel = new AddressTypeModel();
            PhoneTypeModel   newPhoneTypeModel   = new PhoneTypeModel();
            StateModel       newStateModel       = new StateModel();
            AddressModel     newAddressModel     = new AddressModel();
            PhoneModel       newPhoneModel       = new PhoneModel();
            ContactModel     newContactModel     = new ContactModel();
            CustomerModel    newCustomerModel    = new CustomerModel();

            JObject o = (JObject)JToken.FromObject(newAddressTypeModel);

            Console.WriteLine("AddressType Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            o = (JObject)JToken.FromObject(newPhoneTypeModel);
            Console.WriteLine();
            Console.WriteLine("PhoneType Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            o = (JObject)JToken.FromObject(newStateModel);
            Console.WriteLine();
            Console.WriteLine("State Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            o = (JObject)JToken.FromObject(newAddressModel);
            Console.WriteLine();
            Console.WriteLine("Address Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            o = (JObject)JToken.FromObject(newPhoneModel);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Phone Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            o = (JObject)JToken.FromObject(newContactModel);
            Console.WriteLine();
            Console.WriteLine("Contact Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            o = (JObject)JToken.FromObject(newCustomerModel);
            Console.WriteLine();
            Console.WriteLine("Customer Model");
            Console.WriteLine("************************************");
            Console.Write(o.ToString());

            Console.ReadKey();
        }
コード例 #4
0
        public void ConvertModelToEntity_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var            service       = new PhoneTypeService();
            PhoneTypeModel model         = GetTestModel();

            // Act
            phoneType entity = service.ConvertModelToEntity(model);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(entity.name, model.Name);
        }
コード例 #5
0
        public PhoneTypeModel ConvertEntityToModel(phoneType entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new PhoneTypeModel()
            {
                Id   = entity.id,
                Name = entity.name.Trim(),
            };

            return(model);
        }
コード例 #6
0
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new PhoneTypeRepository(context);
            var service    = new PhoneTypeService(repository);
            int id         = 1;

            // Act
            PhoneTypeModel result = service.GetById(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
        }
コード例 #7
0
        /// <summary>
        /// Fetches phone type details by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PhoneTypeModel GetById(int id)
        {
            var phoneType = _dbActions.PhoneTypeRepository.GetById(id);

            if (phoneType != null)
            {
                PhoneTypeModel phoneTypeEntity = new PhoneTypeModel()
                {
                    Id        = phoneType.Id,
                    PhoneType = phoneType.PhoneType,
                    Archived  = phoneType.Archived
                };
                return(phoneTypeEntity);
            }
            return(null);
        }
コード例 #8
0
        public void ConvertEntityToModel_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            //var repository = new PhoneTypeRepository(context);
            var       service = new PhoneTypeService();
            phoneType entity  = context.phoneType.Where(x => x.id == 1).FirstOrDefault();

            // Act
            PhoneTypeModel model = service.ConvertEntityToModel(entity);

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(model.Id, entity.id);
            Assert.AreEqual(model.Name, entity.name);
        }
コード例 #9
0
        public phoneType ConvertModelToEntity(PhoneTypeModel model, int userId = -1)
        {
            phoneType entity = new phoneType();

            if (model == null)
            {
                return(null);
            }

            entity.name = model.Name;

            if (model.Id > 0)
            {
                entity.id = model.Id;
            }

            return(entity);
        }
コード例 #10
0
        /// <summary>
        /// Creates a address type
        /// </summary>
        /// <param name="phoneTypeModel"></param>
        /// <returns></returns>
        public int Create(PhoneTypeModel phoneTypeModel)
        {
            using (var scope = new TransactionScope())
            {
                var phoneType = new PhoneTypeLookup()
                {
                    PhoneType = phoneTypeModel.PhoneType,
                    Archived  = phoneTypeModel.Archived
                };

                var phoneTypeCheck = _dbActions.PhoneTypeRepository.GetSingle(p => p.PhoneType == phoneTypeModel.PhoneType);
                if (phoneTypeCheck == null)
                {
                    _dbActions.PhoneTypeRepository.Insert(phoneType);
                    _dbActions.Save();
                    scope.Complete();
                    return(phoneType.Id);
                }
                scope.Complete();
                return(-1);
            }
        }
コード例 #11
0
        /// <summary>
        /// Updates a lookup type
        /// </summary>
        /// <param name="id"></param>
        /// <param name="phoneTypeModel"></param>
        /// <returns></returns>
        public bool Update(int id, PhoneTypeModel phoneTypeModel)
        {
            var success = false;

            if (phoneTypeModel != null)
            {
                using (var scope = new TransactionScope())
                {
                    var phoneType = _dbActions.PhoneTypeRepository.GetById(id);
                    if (phoneType != null)
                    {
                        phoneType.PhoneType = phoneTypeModel.PhoneType;
                        phoneType.Archived  = phoneTypeModel.Archived;
                        _dbActions.PhoneTypeRepository.Update(phoneType);
                        _dbActions.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return(success);
        }
コード例 #12
0
        /// <summary>
        /// Fetches all the phone types.
        /// </summary>
        /// <param name="includeArchived"></param>
        /// <returns></returns>
        public IEnumerable <PhoneTypeModel> GetAll(bool includeArchived)
        {
            var phoneTypes = includeArchived ? _dbActions.PhoneTypeRepository.GetAll().ToList()
                                             : _dbActions.PhoneTypeRepository.GetMany(p => p.Archived == false).ToList();

            if (!phoneTypes.Any())
            {
                return(null);
            }
            List <PhoneTypeModel> phoneTypeEntities = new List <PhoneTypeModel>();

            foreach (PhoneTypeLookup phoneType in phoneTypes)
            {
                PhoneTypeModel phoneTypeEntity = new PhoneTypeModel()
                {
                    Id        = phoneType.Id,
                    PhoneType = phoneType.PhoneType,
                    Archived  = phoneType.Archived
                };
                phoneTypeEntities.Add(phoneTypeEntity);
            }

            return(phoneTypeEntities);
        }
コード例 #13
0
 // PUT: api/LookupType/5
 public bool Put(int id, [FromBody] PhoneTypeModel phoneType)
 {
     return(id > 0 && _phoneTypeServices.Update(id, phoneType));
 }
コード例 #14
0
 public int Insert(PhoneTypeModel model, int userId)
 {
     return(-1);
 }
コード例 #15
0
 public int Update(PhoneTypeModel model, int userId)
 {
     return(-1);
 }