private void SaveReceipts(Models.ProductServiceModel prodServiceModel) { Entities.Products_Services prodService = new Entities.Products_Services(); //TODO: Hack: Fix it later. Allow null value in Name field prodService.Name = string.IsNullOrEmpty(prodServiceModel.ServiceName) ? string.Empty : prodServiceModel.ServiceName; prodService.Description = prodServiceModel.ServiceDescription; prodService.PurchaseDate = prodServiceModel.ServicePurchaseDate; prodService.Tags = prodServiceModel.ServiceTags; prodService.CreatedOn = DateTime.Now; prodService.CategoryId = 1; //prodServiceModel.ServiceCategoryId; prodService.SubCategoryId = 1; //prodServiceModel.ServiceSubCategoryId; Entities.Receipt receipt = new Entities.Receipt(); receipt.Title = prodServiceModel.ReceiptTitle; receipt.SerialNumber = prodServiceModel.ReceiptSerialNumber; receipt.Description = prodServiceModel.ReceiptDescription; receipt.ReceiptDate = prodServiceModel.ReceiptDate; List <Entities.Image> receiptImageList = new List <Entities.Image>(); if (prodServiceModel.ReceiptUploadedFiles != null) { foreach (Models.Image imageModel in prodServiceModel.ReceiptUploadedFiles) { Entities.Image image = imageModel; receiptImageList.Add(image); } } Entities.WarrantyCard warrantyCard = new Entities.WarrantyCard(); warrantyCard.Description = prodServiceModel.ReceiptDescription; warrantyCard.Title = prodServiceModel.WarrantyTitle; warrantyCard.WarrantyExpireOn = prodServiceModel.WarrantyExpireOn; warrantyCard.CardNumber = prodServiceModel.WarrantyCardNumber; List <Entities.Image> warranyCardImageList = new List <Entities.Image>(); if (prodServiceModel.WarrantyCardUploadedFiles != null) { foreach (Models.Image imageModel in prodServiceModel.WarrantyCardUploadedFiles) { Entities.Image image = imageModel; warranyCardImageList.Add(image); } } Managers.MyProductServiceManager manager = new Managers.MyProductServiceManager(); manager.Insert(Context.GetContext(), prodService, receipt, warrantyCard, receiptImageList, warranyCardImageList); }
/// <summary> /// No Metadata Documentation available. /// </summary> /// <param name="apiContext"></param> /// <param name="image"></param> /// <param name="result"></param> public static void ValidateData(Helpers.ApiContext apiContext, Entities.Image image, ref Helpers.ActionResult result) { OnValidating(apiContext, image, ref result); if (image.Id == null) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Id is required.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (!System.String.IsNullOrWhiteSpace(image.Title) && image.Title.Length > 50) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Title must be 50 characters or less.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (!System.String.IsNullOrWhiteSpace(image.Title) && !System.Text.RegularExpressions.Regex.IsMatch(image.Title, alphaNumeric)) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Title contains invalid characters.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (System.String.IsNullOrWhiteSpace(image.Path)) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Path is required.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (!System.String.IsNullOrWhiteSpace(image.Path) && image.Path.Length > 100) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Path must be 100 characters or less.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (!System.String.IsNullOrWhiteSpace(image.Path) && !System.Text.RegularExpressions.Regex.IsMatch(image.Path, alphaNumeric)) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Path contains invalid characters.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (!System.String.IsNullOrWhiteSpace(image.FileFormat) && image.FileFormat.Length > 5) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "FileFormat must be 5 characters or less.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } if (!System.String.IsNullOrWhiteSpace(image.FileFormat) && !System.Text.RegularExpressions.Regex.IsMatch(image.FileFormat, alphaNumeric)) { result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "FileFormat contains invalid characters.", Helpers.ActionResultMessageType.Error)); result.WasSuccessful = false; } OnValidated(apiContext, image, ref result); }
public void InsertImage() { ReceiptManagement.Common.Entities.Image image = new ReceiptManagement.Common.Entities.Image(); image.CreatedOn = DateTime.Now; image.FileSize = 1000; image.Title = "Faisal"; image.Path = "C:\\"; image.FileFormat = "jpg"; image.IsDeleted = false; long id = 0; new ImageManager().Insert(apiContext, image, out id); }
/// <summary> /// No Metadata Documentation available. /// </summary> /// <param name="apiContext"></param> /// <param name="id"></param> /// <param name="image"></param> /// <returns></returns> public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.Image image) { // API doesn't allow null parameters. if (apiContext == null) { throw new System.ArgumentNullException("apiContext"); } if (id == null) { throw new System.ArgumentNullException("id"); } // Verify user is authorized to perform action, otherwise throw exception. Security.SecurityHandler.SetApiContext(apiContext); Helpers.ActionResult result = Helpers.ActionResult.Factory(true); try { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; var qry = context.Images.Where(r => r.Id.Equals(id)).FirstOrDefault(); // See what would be default value in this case // Also to see if no value found what shall be put into Action Result if (qry != null) { image = qry; // must detach the object before return DetachObject(apiContext, image); } else { image = new Entities.Image(); image.Id = id; result.WasSuccessful = false; result.Messages.Add(Helpers.ActionResultMessage.Factory(image, "Object not Found", Helpers.ActionResultMessageType.Warning)); } } catch (System.Exception ex) { object forDebugging = ex; throw; // Helpers.Exceptions.GetEntityException.Factory(ex); } return(result); }
public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.Image image, out long id) { // API doesn't allow null parameters. This method requires at least 1 item in the collection. if (apiContext == null) { throw new System.ArgumentNullException("apiContext"); } if (image == null) { throw new System.ArgumentNullException("image"); } // Verify user is authorized to perform action, otherwise throw exception. Security.SecurityHandler.SetApiContext(apiContext); Helpers.ActionResult result = Helpers.ActionResult.Factory(true); try { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; // ADD to context OnAdding(apiContext, image); context.AddObject("Images", image); context.SaveChanges(); // Save Changes id = image.Id; DetachObjects(apiContext, new System.Collections.Generic.List <Entities.Image> { image }); // Clean ObjectState cache } catch (System.Exception ex) { object forDebugging = ex; throw; // Helpers.Exceptions.AddEntityException.Factory(ex); } return(result); }
/// <summary> /// No Metadata Documentation available. /// </summary> /// <param name="apiContext"></param> /// <param name="whereClause"></param> /// <param name="entity"></param> /// <returns></returns> public static bool IsExists(Helpers.ApiContext apiContext, System.Linq.Expressions.Expression <System.Func <Entities.Image, bool> > whereClause, out Entities.Image entity) { // API doesn't allow null parameters. This method requires at least 1 item in the collection. if (apiContext == null) { throw new System.ArgumentNullException("apiContext"); } if (whereClause == null) { throw new System.ArgumentNullException("whereClause"); } // Verify user is authorized to perform action, otherwise throw exception. Security.SecurityHandler.SetApiContext(apiContext); try { Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext; var query = context.Images.Where(whereClause).FirstOrDefault(); if (query != null) { entity = query; DetachObject(apiContext, entity); // must detach the object before return } else { entity = null; } return(query != null); } catch (System.Exception ex) { object forDebugging = ex; throw; // Helpers.Exceptions.ExistsException.Factory(ex); } }
// This partial method gives us a way to access an object after it has been purged from the system. static partial void OnPurged(Helpers.ApiContext apiContext, Entities.Image image);
// This partial method gives us a way to access an object after it has been validated in the system. static partial void OnValidated(Helpers.ApiContext apiContext, Entities.Image image, ref Helpers.ActionResult result);
// This partial method gives us a way to access an object during it is bulk updated in the system. static partial void OnPartialUpdate(Helpers.ApiContext apiContext, Entities.Image image);
// This partial method gives us a way to update an object before it is imported into the system. static partial void OnImporting(Helpers.ApiContext apiContext, Entities.Image image);
// This partial method gives us a way to access an object after it has been updated in the system. static partial void OnUpdated(Helpers.ApiContext apiContext, Entities.Image image, bool isBulkUpdate);