コード例 #1
0
        /// <summary>
        ///Method to create the seller partner in sitecore database
        /// </summary>
        /// <param name="sellerPartner"></param>
        /// <returns></returns>
        public SellerPartner CreateSellerPartner(SellerPartner sellerPartner)
        {
            var sellerPartnerCollection = Context.Database.GetItem(Templates.SellerPartnerCollectionItemId);

            if (sellerPartnerCollection == null)
            {
                throw new NullReferenceException("Seller Partner Collection not found!");
            }
            using (new SecurityDisabler())
            {
                sellerPartnerCollection.Editing.BeginEdit();
                var sellerPartnerToCreate =
                    sellerPartnerCollection.Add(sellerPartner.Title, new TemplateID(Templates.SellerPartnerTemplateId));
                if (sellerPartnerToCreate == null)
                {
                    throw new NullReferenceException("Failed to add the seller partner!");
                }
                sellerPartnerCollection.Editing.EndEdit();

                sellerPartnerToCreate.Editing.BeginEdit();
                sellerPartnerToCreate[Templates.SellerPartner.Fields.Title]       = sellerPartner.Title;
                sellerPartnerToCreate[Templates.SellerPartner.Fields.Description] = sellerPartner.Description;
                sellerPartnerToCreate[Templates.SellerPartner.Fields.Country]     = sellerPartner.Country;
                sellerPartnerToCreate.Editing.EndEdit();

                sellerPartner.Id = sellerPartnerToCreate.ID.ToString();
            }

            return(sellerPartner);
        }
コード例 #2
0
 public HttpResponseMessage Post(SellerPartner sellerPartner)
 {
     if (string.IsNullOrEmpty(sellerPartner.Title))
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponseModel
         {
             ErrorCode = ErrorCodes.InputModelError,
             UserMessage = "Seller Partner Title is required!"
         }));
     }
     // Always wrap controller code in try/catch blocks
     // in order to obtain control over responses when
     // exceptions occur
     try
     {
         // Try to edit the seller partner
         var result = this.Repository.CreateSellerPartner(sellerPartner);
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     // This catch block catches a specific exception
     // Use it for exceptions you are able to predict
     // and handle in a specific way
     catch (NullReferenceException ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ErrorCodes.NotFoundError, ex));
     }
     // This catches other types of exceptions that was not predicted
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorCodes.UnknownError, ex));
     }
 }
コード例 #3
0
        public HttpResponseMessage Put(SellerPartner sellerPartner)
        {
            Guid tmpGuid;

            if (!Guid.TryParse(sellerPartner.Id, out tmpGuid))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponseModel
                {
                    ErrorCode = ErrorCodes.InvalidId,
                    UserMessage = "Invalid ID!"
                }));
            }
            // Always wrap controller code in try/catch blocks
            // in order to obtain control over responses when
            // exceptions occur
            try
            {
                // Try to edit the seller partner
                var result = this.Repository.EditSellerPartner(sellerPartner);
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            // This catch block catches a specific exception
            // Use it for exceptions you are able to predict
            // and handle in a specific way
            catch (NullReferenceException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ErrorCodes.NotFoundError, ex));
            }
            // This catches other types of exceptions that was not predicted
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorCodes.UnknownError, ex));
            }
        }
コード例 #4
0
        /// <summary>
        ///Method to edit the seller partner from sitecore database
        /// </summary>
        /// <param name="sellerPartner"></param>
        /// <returns></returns>
        public SellerPartner EditSellerPartner(SellerPartner sellerPartner)
        {
            var sellerPartnerToEdit = Context.Database.GetItem(sellerPartner.Id);

            if (sellerPartnerToEdit == null)
            {
                throw new NullReferenceException("Seller Partner not found!");
            }
            using (new SecurityDisabler())
            {
                sellerPartnerToEdit.Editing.BeginEdit();
                sellerPartnerToEdit[Templates.SellerPartner.Fields.Title]       = sellerPartner.Title;
                sellerPartnerToEdit[Templates.SellerPartner.Fields.Description] = sellerPartner.Description;
                sellerPartnerToEdit[Templates.SellerPartner.Fields.Country]     = sellerPartner.Country;
                sellerPartnerToEdit.Editing.EndEdit();
            }

            return(sellerPartner);
        }