public void Delete(Opportunity opportunityToDelete)
        {
            var originalOpportunity = Get(opportunityToDelete.Id);
            _entities.DeleteObject(originalOpportunity);
            _entities.SaveChanges();

        }
        public Opportunity Create(Opportunity opportunityToCreate)
        {
            _entities.AddToOpportunitySet(opportunityToCreate);
            _entities.SaveChanges();
            return opportunityToCreate;

        }
        public Opportunity Update(Opportunity opportunityToUpdate)
        {
            var originalOpportunity = Get(opportunityToUpdate.Id);
            _entities.ApplyCurrentValues(originalOpportunity.EntityKey.EntitySetName, opportunityToUpdate);
            _entities.SaveChanges();
            return opportunityToUpdate;

        }
        public OpportunityViewModel(Opportunity opportunity)
        {
            //creating the elements for opportunity status drop down list
            var statuses = Enum.GetNames(typeof(OpportunityStatus));

            Opportunity = opportunity;
            Statuses = new SelectList(statuses, Opportunity.Status);

        }
        public bool ValidateOpportunity(Opportunity opportunityToValidate)
        {
            //convert null values to empty strings
            opportunityToValidate.Description = opportunityToValidate.Description ?? "";

            if (opportunityToValidate.Amount <= 0)
                _validationDictionary.AddError("Opportunity.Amount", "Amount must be greater than 0.");
            if (opportunityToValidate.Description.Trim().Length == 0)
                _validationDictionary.AddError("Opportunity.Description", "Description is required.");
            return _validationDictionary.IsValid;
        }
 public bool DeleteOpportunity(Opportunity opportunityToDelete)
 {
     try
     {
         _repository.Delete(opportunityToDelete);
     }
     catch
     {
         return false;
     }
     return true;
 }
        public bool EditOpportunity(Opportunity opportunityToEdit)
        {
            // Validation logic
            if (!ValidateOpportunity(opportunityToEdit))
                return false;

            // Database logic
            try
            {
                _repository.Update(opportunityToEdit);
            }
            catch
            {
                return false;
            }
            return true;
        }
        public bool CreateOpportunity(Opportunity opportunityToCreate)
        {
            // Validation logic
            if (!ValidateOpportunity(opportunityToCreate))
                return false;

            // Database logic
            try
            {
                _repository.Create(opportunityToCreate);
            }
            catch
            {
                return false;
            }
            return true;
        }
 public ActionResult Delete(Opportunity opportunity)
 {
     if (!_opportunityService.DeleteOpportunity(opportunity))
         return View(opportunity);
     return RedirectToAction("Index");
 }
 /// <summary>
 /// Create a new Opportunity object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="amount">Initial value of the Amount property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 public static Opportunity CreateOpportunity(global::System.Int32 id, global::System.Double amount, global::System.String status, global::System.String description)
 {
     Opportunity opportunity = new Opportunity();
     opportunity.Id = id;
     opportunity.Amount = amount;
     opportunity.Status = status;
     opportunity.Description = description;
     return opportunity;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the OpportunitySet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOpportunitySet(Opportunity opportunity)
 {
     base.AddObject("OpportunitySet", opportunity);
 }