Ejemplo n.º 1
0
 public void DeleteCategory(ContactCategory category)
 {
     if (category == null || category.Id == 0)
     {
         return;
     }
     _categoryRepository.DeleteById(category.Id);
 }
Ejemplo n.º 2
0
        public ActionResult Edit(ContactCategory cat)
        {
            Uri uri = new Uri("http://localhost:53578/api/");

            using (var client = new HttpClient())
            {
                client.BaseAddress = uri;
                var result = client.PutAsJsonAsync("PBA/" + cat.CategoryId, cat).Result;
                return(RedirectToAction("ContactCategories"));
            }
        }
Ejemplo n.º 3
0
 public void UpdateCategoryById(ContactCategory cat)
 {
     try
     {
         PBADataAccessLayer dal = new PBADataAccessLayer();
         dal.UpdateCategoryById(cat);
     }
     catch (PBAException ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
 public void AddContactCategory(ContactCategory cat)
 {
     try
     {
         PBADataAccessLayer dal = new PBADataAccessLayer();
         dal.AddContactCategory(cat);
     }
     catch (PBAException ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 5
0
        public HttpResponseMessage Put([FromBody] ContactCategory cat, int id)
        {
            HttpResponseMessage errRes = Request.CreateErrorResponse(HttpStatusCode.OK, "Records Updated");

            try
            {
                PBABusiness bll = new PBABusiness();
                bll.UpdateCategoryById(cat);
            }
            catch (Exception ex)
            {
                errRes = Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message);
            }
            return(errRes);
        }
Ejemplo n.º 6
0
        public HttpResponseMessage Post([FromBody] ContactCategory cat)
        {
            HttpResponseMessage errRes = Request.CreateErrorResponse(HttpStatusCode.OK, "Record Inserted");

            try
            {
                PBABusiness bll = new PBABusiness();
                bll.AddContactCategory(cat);
            }
            catch (Exception ex)
            {
                errRes = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Record not found");
            }
            return(errRes);
        }
Ejemplo n.º 7
0
        public IActionResult Post([FromBody] ContactCategory value)
        {
            if (value.Id == 0)
            {
                _contactCategoryRepository.InsertContactCategory(value);
            }
            else
            {
                _contactCategoryRepository.UpdateContactCategory(value);
            }

            _contactCategoryRepository.Save();

            return(Ok());
        }
        /// <summary>
        /// Displaying the records of Contact Category
        /// </summary>
        public List <ContactCategory> GetAllcategoryNames()
        {
            List <ContactCategory> lstcat = new List <ContactCategory>();

            try
            {
                //configure command for SELECT statement
                cmd             = new SqlCommand();
                cmd.CommandText = "select * from ContactCategory";
                //attach the connection with the command
                cmd.Connection = con;

                //open the connection
                con.Open();

                //execute the command
                SqlDataReader sdr = cmd.ExecuteReader();
                //read the records from data reader and add them to the collection
                while (sdr.Read())
                {
                    ContactCategory c = new ContactCategory
                    {
                        CategoryId   = (int)sdr[0],
                        CategoryName = sdr[1].ToString(),
                    };
                    lstcat.Add(c);
                }
                //close the data reader
                sdr.Close();
            }
            catch (SqlException ex)
            {
                throw new PBAException(ex.Message);
            }
            catch (Exception ex)
            {
                throw new PBAException(ex.Message);
            }
            finally
            {
                //close the connection
                con.Close();
            }
            //returning all the records using collection
            return(lstcat);
        }
Ejemplo n.º 9
0
        public ActionResult Create(ContactCategory cat)
        {
            //calling API POST for Insert Categoryrecord
            Uri uri = new Uri("http://localhost:53578/api/");

            using (var client = new HttpClient())
            {
                client.BaseAddress = uri;
                var result = client.PostAsJsonAsync("PBA/", cat).Result;
                if (result.IsSuccessStatusCode == true)
                {
                    return(RedirectToAction("ContactCategories"));
                }
                else
                {
                    ViewData.Add("msg", "Could not insert record,Some error Occured");
                }
                return(View());
            }
        }
        private List <Contact> CreateTestContactsWithDetails(FamilyDbContext context)
        {
            // Create test entities
            var category1 = new ContactCategory
            {
                CategoryName = "Friends",
            };
            var contact1 = new Contact
            {
                ContactCategory = category1
            };

            // Persist entities
            context.Contacts.Add(contact1);
            context.SaveChanges();

            // Create one-to-one related entity
            var data1 = new ContactData
            {
                Data      = "Data 1",
                ContactId = contact1.Id,
                Contact   = contact1
            };

            context.ContactDatas.Add(data1);
            context.SaveChanges();

            // Detach entities
            var objContext = ((IObjectContextAdapter)context).ObjectContext;

            objContext.Detach(contact1);

            // Clear reference properties
            contact1.ContactCategory = null;
            contact1.ContactData     = null;

            // Return entities
            return(new List <Contact> {
                contact1
            });
        }
Ejemplo n.º 11
0
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            ContactCategory category = (ContactCategory)value;
            Color           c        = Colors.Black;

            switch (category)
            {
            case ContactCategory.Friend: c = Colors.Green; break;

            case ContactCategory.Family: c = Colors.Blue; break;

            case ContactCategory.Colleague: c = Colors.Orange; break;

            case ContactCategory.Customer: c = Colors.Black; break;

            case ContactCategory.MedicalPractitioner:
                c = Colors.Red; break;
            }

            return(new SolidColorBrush(c));
        }
 /// <summary>
 /// Inserting records into the ContactCategory
 /// </summary>
 /// <param name="cat"></param>
 public void AddContactCategory(ContactCategory cat)
 {
     try
     {
         //configure command for INSERT statemnt
         cmd             = new SqlCommand();
         cmd.CommandText = "insert into ContactCategory values(@catid,@catname)";
         //Attach the connection with the command
         cmd.Connection = con;
         cmd.Parameters.Clear();
         //supplying the values to the parameters of the command
         cmd.Parameters.AddWithValue("@catid", cat.CategoryId);
         cmd.Parameters.AddWithValue("@catname", cat.CategoryName);
         cmd.CommandType = CommandType.Text;
         //open the connection
         con.Open();
         //Execute the Command
         int recordsAffected = cmd.ExecuteNonQuery();
         if (recordsAffected == 0)
         {
             throw new PBAException("Could not insert data");
         }
     }
     catch (SqlException ex)
     {
         throw new PBAException("some error has happened" + ex.Message);
     }
     catch (Exception ex)
     {
         throw new PBAException("some error has happened" + ex.Message);
     }
     finally
     {
         //close the connection
         con.Close();
     }
 }
 /// <summary>
 /// Updating the Category By Id
 /// </summary>
 /// <param name="cat"></param>
 public void UpdateCategoryById(ContactCategory cat)
 {
     try
     {
         //Update the Category By Id
         cmd             = new SqlCommand();
         cmd.CommandText = "update ContactCategory set CategoryId=@catid,CategoryName=@catname where CategoryId=@ci";
         cmd.CommandType = CommandType.Text;
         //Attach the connection to the command
         cmd.Connection = con;
         cmd.Parameters.Clear();
         //Supply values of the Parameters to the command
         cmd.Parameters.AddWithValue("@catid", cat.CategoryId);
         cmd.Parameters.AddWithValue("@ci", cat.CategoryName);
         //Open the connection
         con.Open();
         //Execute the command
         int recordsAffected = cmd.ExecuteNonQuery();
         if (recordsAffected == 0)
         {
             throw new PBAException("Could not update category");
         }
     }
     catch (SqlException ex)
     {
         throw new PBAException("Some error has happened" + ex.Message);
     }
     catch (Exception ex)
     {
         throw new PBAException("Some error has happened" + ex.Message);
     }
     finally
     {
         //Close the connection
         con.Close();
     }
 }
Ejemplo n.º 14
0
 public void UpdateCategory(ContactCategory category)
 {
     _categoryRepository.AddOrUpdate(category);
 }
 public void InsertContactCategory(ContactCategory ContactCategory)
 {
     context.ContactCategories.Add(ContactCategory);
 }
        public void DeleteContactCategory(int ContactCategoryID)
        {
            ContactCategory ContactCategory = context.ContactCategories.Find(ContactCategoryID);

            context.ContactCategories.Remove(ContactCategory);
        }
 public void UpdateContactCategory(ContactCategory ContactCategory)
 {
     context.Entry(ContactCategory).State = EntityState.Modified;
 }
Ejemplo n.º 18
0
 public CustomList <ContactCategory> GetAllContactCategory()
 {
     return(ContactCategory.GetAllContactCategory());
 }
Ejemplo n.º 19
0
 public string GetEmailReceiverAddress(ContactCategory contactCategory)
 {
     return(_emailAddressesForContactCategories[contactCategory]);
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a new <see cref="Category" /> instance from the provided model.
        /// </summary>
        /// <param name="model">The model coming from the API.</param>
        /// <returns>Returns the created category instance.</returns>
        private Category GetCategory(Models.Categories.Category model)
        {
            // Initializes the category
            Category category;

            // Checks whether the category is a contact category
            switch (model.objectType)
            {
            case "Contact":
                category = new ContactCategory();
                break;

            case "Document":
                category = new DocumentCategory();
                break;

            case "ProjectTime":
                category = new ProjectTimeCategory();
                break;

            case "Task":
                category = new TaskCategory();
                break;

            case "Part":
                category = new PartCategory();
                break;

            case "Project":
                category = new ProjectCategory();
                break;

            case "ContactAddress":
                switch (model.translationCode)
                {
                case "CATEGORY_WORK":
                    category = new WorkAddressCategory();
                    break;

                case "CATEGORY_PRIVAT":
                    category = new PrivateAddressCategory();
                    break;

                case "CATEGORY_INVOICE_ADDRESS":
                    category = new InvoiceAddressCategory();
                    break;

                case "CATEGORY_DELIVERY_ADDRESS":
                    category = new DeliveryAddressCategory();
                    break;

                case "CATEGORY_PICKUP_ADDRESS":
                    category = new PickupAddressCategory();
                    break;

                case "CATEGORY_EMPTY":
                default:
                    return(null);
                }
                break;

            default:
                return(null);
            }

            // Sets the category specific properties
            category.Id = model.id;
            category.CreationDateTime = string.IsNullOrWhiteSpace(model.create) ? (Nullable <DateTime>)null : DateTime.Parse(model.create);
            category.UpdateDateTime   = string.IsNullOrWhiteSpace(model.update) ? (Nullable <DateTime>)null : DateTime.Parse(model.update);
            category.Name             = model.name;
            category.Color            = model.color;
            category.Code             = model.code;
            category.Priority         = int.Parse(model.priority);

            // Returns the created category
            return(category);
        }