/// <summary>
 /// Delete pictures
 /// </summary>
 /// <param name="pictureIds">Pictures identifiers</param>
 /// <param name="userName">User name logged in the application</param>
 public static void DeletePictures(string pictureIds, string userName)
 {
     //Split the pictures ids according the separator "&&&"
     string[] values = pictureIds.Split(new string[] { "&&&" }, StringSplitOptions.RemoveEmptyEntries);
     Guid[] valuesGuid = values.Select(x => new Guid(x)).ToArray();
     Picture pictureResult = null;
     using (VestalisEntities context = new VestalisEntities())
     {
         foreach (Guid pictureId in valuesGuid)
         {
             //Get the picture according the picture identifier
             pictureResult =
             (from picture in context.Pictures where picture.PictureId == pictureId select picture).
                 FirstOrDefault();
             if (pictureResult != null)
             {
                 //Set the picture as deleted
                 pictureResult.IsDeleted = true;
                 pictureResult.ModificationDate = DateTime.UtcNow;
                 pictureResult.ModificationBy = userName;
             }
         }
         context.SaveChanges();
     }
 }
Пример #2
0
        /// <summary>
        /// Delete the permission for a business application
        /// </summary>
        /// <param name="userName">Selected user name</param>
        /// <param name="businessApplicationId">Id of business application</param>
        /// <param name="loggedUserName">Logged user</param>
        /// <param name="userType">Type of user</param>
        public static void DeletePermission(string userName, Guid businessApplicationId, string loggedUserName, int userType)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                //get the current business application to delete
                var currentBusinessApp = (from businessApp in context.VestalisUserApplications
                                          where businessApp.IsDeleted == false && businessApp.UserName == userName
                                          && businessApp.BusinessApplicationId == businessApplicationId
                                          select businessApp).FirstOrDefault();

                if (currentBusinessApp != null)
                {
                    //delete the business application
                    currentBusinessApp.IsDeleted = true;
                    currentBusinessApp.ModificationBy = loggedUserName;
                    currentBusinessApp.ModificationDate = DateTime.UtcNow;

                    context.SaveChanges();

                    //delete the permissions for the business applications
                    if (userType > 3)
                    {
                        string prefix = "_";
                        prefix += GetAllBusinessAplications().FirstOrDefault(data => data.BusinessApplicationId == businessApplicationId).Prefix;
                        string[] currentRoles = Roles.GetRolesForUser(userName).Where(role => role.Contains(prefix)).ToArray();
                        Roles.RemoveUserFromRoles(userName, currentRoles);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Delete a catalogue 
        /// </summary>
        /// <param name="catalogueId">id of catalog</param>
        /// <param name="businessApplicationId">Id of business application</param>
        /// <param name="userName">Name of logged user</param>
        public static string DeleteCategoryCatalogue(Guid catalogueId,Guid businessApplicationId, string userName)
        {
            Catalogue catalogueToDelete = null;
            string message = string.Empty;
            using (VestalisEntities context = new VestalisEntities())
            {
                catalogueToDelete = context.Catalogues.FirstOrDefault(data => data.IsDeleted == false && data.CatalogueId == catalogueId);
                if (catalogueToDelete != null)
                {
                    //Get the fields definition for the business application
                    Fields fieldBusinessApplication = CacheHandler.Get(String.Format("Field{0}", businessApplicationId),
                                                    () => DynamicFormEngine.GetFields(businessApplicationId));

                    List<FieldsCatalogueField> catalogueFields = fieldBusinessApplication.Items
                        .Where(data => data is FieldsCatalogueField)
                        .Cast<FieldsCatalogueField>()
                        .ToList();

                    if (!catalogueFields.Any(data => data.CatalogueName == catalogueToDelete.CatalogueCategoryName))
                    {
                        catalogueToDelete.IsDeleted = true;
                        catalogueToDelete.ModificationBy = userName;
                        catalogueToDelete.ModificationDate = DateTime.UtcNow;
                        context.SaveChanges();
                    }
                    else
                    {
                        message = string.Format(Resources.LanguageResource.CatalogueCategoryNonDeleteMultipleMessage,
                            catalogueToDelete.CatalogueCategoryName);
                    }
                }
            }
            return message;
        }
Пример #4
0
        /// <summary>
        /// Delete a value from a catalog
        /// </summary>
        /// <param name="catalogValueId">id of catalog value</param>
        /// <param name="businessApplicationId">Id of business application</param>
        /// <param name="userName">The name of the user</param>
        public static string DeleteCatalogueValue(Guid catalogValueId, Guid businessApplicationId, string userName)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                bool existValueServiceOrder = false;
                bool existValueInspectionReport = false;

                VerifyCatalogueValue(catalogValueId, businessApplicationId, context, ref existValueServiceOrder, ref existValueInspectionReport);

                CatalogueValue catalogueValueDeleted = context.CatalogueValues.FirstOrDefault(data => data.IsDeleted == false && data.CatalogueValueId == catalogValueId);
                if (!existValueServiceOrder && !existValueInspectionReport)
                {

                    //if the current catalogue is not null, the system continues with the process
                    if (catalogueValueDeleted != null)
                    {
                        //set IsDeleted in true
                        catalogueValueDeleted.IsDeleted = true;
                        //set auditory fields
                        catalogueValueDeleted.ModificationBy = userName;
                        catalogueValueDeleted.ModificationDate = DateTime.UtcNow;
                    }
                    context.SaveChanges();
                    return string.Empty;
                }
                else
                {
                    return string.Format(LanguageResource.CatalogueValueNonDeleteMultipleMessage, catalogueValueDeleted.CatalogueValueData);
                }
            }
        }
        /// <summary>
        /// Create a new Inspection report item
        /// </summary>
        /// <param name="parameters">Parameters to save the information</param>
        public static Guid AddInspectionReport(ParameterSaveInspectionReport parameters)
        {
            Guid inspectionReportId = GetInspectionReportByName(parameters.InspectionReportName, parameters.ServiceOrderId).InspectionReportId;
            Fields fieldBusinessApplication = CacheHandler.Get(String.Format("Field{0}", parameters.BusinessApplicationId),
                                            () => DynamicFormEngine.GetFields(parameters.BusinessApplicationId));

            string fieldName = string.Empty;
            string valData = string.Empty;
            Guid inspectionReportItemId = Guid.NewGuid();
            InspectionReportItem inspectionReportItem = null;
            using (VestalisEntities context = new VestalisEntities())
            {
                inspectionReportItem = new InspectionReportItem
                {
                    InspectionReportId = inspectionReportId,
                    StatusCode = ConstantApplication.InspectionReportPendingPublish,
                    CreationBy = parameters.UserName,
                    CreationDate = DateTime.UtcNow,
                    InspectionReportItemId = inspectionReportItemId
                };
                context.InspectionReportItems.AddObject(inspectionReportItem);

                AddApprovalItem(parameters, inspectionReportItemId, context, inspectionReportItem);

                foreach (var formCollectionValue in parameters.FormCollection.Keys)
                {
                    fieldName = formCollectionValue.ToString();
                    ValueProviderResult val = parameters.FormCollection.GetValue(fieldName);
                    if (val != null)
                    {
                        //Get the form value for the specific field
                        valData = val.AttemptedValue.ToString();
                        if (!String.IsNullOrEmpty(valData))
                        {
                            //Set the form value
                            FormValue formValue = SetFormValueToInspectionReport(parameters, inspectionReportItemId, fieldName, valData,
                                                                          fieldBusinessApplication);
                            //Add the form value to the context
                            context.FormValues.AddObject(formValue);
                        }
                    }
                }
                context.SaveChanges();
            }
            return inspectionReportItem.InspectionReportItemId;
        }
Пример #6
0
        /// <summary>
        /// Get the fields of the business application
        /// </summary>
        /// <param name="businessApplicationId">Business application identifier</param>
        /// <returns>Fields of a business application</returns>
        public static Fields GetFields(Guid businessApplicationId)
        {
            Fields fieldReturn = null;
            using (VestalisEntities ctx = new VestalisEntities())
            {
                //Execute search in the database the fields used in a business application
                BusinessApplication businessApplicationProcess = (from businessApplication in ctx.BusinessApplications
                                                                  where businessApplication.BusinessApplicationId == businessApplicationId
                                                                  select businessApplication).FirstOrDefault();
                if (businessApplicationProcess != null)
                {

                    //Convert to a Field object
                    fieldReturn = XmlHelper.ReadFormFromXml<Fields>(businessApplicationProcess.XmlFieldDefinition);
                }
                return fieldReturn;
            }
        }
 /// <summary>
 /// Delete a document
 /// </summary>
 /// <param name="documentId">Document identifier</param>
 /// <param name="userName">User name logged in the application</param>
 public static void DeleteDocument(Guid documentId, string userName)
 {
     Document documentToDelete = null;
     using (VestalisEntities context = new VestalisEntities())
     {
         //Get the document from the database
         documentToDelete = context.Documents.FirstOrDefault(data => data.IsDeleted == false && data.DocumentId == documentId);
         if (documentToDelete != null)
         {
             //Set the is_deleted flag as true
             documentToDelete.IsDeleted = true;
             //Set the audit fields
             documentToDelete.ModificationBy = userName;
             documentToDelete.ModificationDate = DateTime.UtcNow;
             context.SaveChanges();
         }
     }
 }
 /// <summary>
 /// Delete service order
 /// </summary>
 /// <param name="inspectionReporItemtId">Inspection report item id</param>
 /// <param name="userName">User name</param>
 public static void DeleteInspectionReport(Guid inspectionReporItemtId, string userName)
 {
     using (VestalisEntities ctx = new VestalisEntities())
     {
         //Get the service order
         InspectionReportItem inspectionReportItem =
             (from inspectionReportItemQuery in ctx.InspectionReportItems
              where inspectionReportItemQuery.InspectionReportItemId == inspectionReporItemtId
              select inspectionReportItemQuery).FirstOrDefault();
         if (inspectionReportItem != null)
         {
             //Delete the record
             inspectionReportItem.IsDeleted = true;
             inspectionReportItem.ModificationBy = userName;
             inspectionReportItem.ModificationDate = DateTime.UtcNow;
             ctx.SaveChanges();
         }
     }
 }
Пример #9
0
        /// <summary>
        /// Get the xml that was used when the service order was created
        /// </summary>
        /// <param name="serviceOrderId">Service order identifier</param>
        /// <returns>Form definition of the existing service order</returns>
        public static Form GetExistingServiceOrderForm(Guid serviceOrderId)
        {
            Form formReturn = null;

            using (VestalisEntities ctx = new VestalisEntities())
            {
                string xmlFormDefinitionInstance =
                    (from serviceOrder in ctx.ServiceOrders
                     where serviceOrder.ServiceOrderId == serviceOrderId
                     select serviceOrder.XmlFormDefinitionInstance).FirstOrDefault();
                if (xmlFormDefinitionInstance != null)
                {
                    //Convert to a Form object
                    formReturn = XmlHelper.ReadFormFromXml<Form>(xmlFormDefinitionInstance);
                }
            }

            return formReturn;
        }
Пример #10
0
        /// <summary>
        /// Get the xml that was used when the service order and inspection reports were created
        /// </summary>
        /// <param name="inspectionReportItemId">Inspection report item identifier</param>
        /// <returns>Form definition of the existing service order</returns>
        public static Form GetExistingInspectionReportForm(Guid inspectionReportItemId)
        {
            Form formReturn = null;

            using (VestalisEntities ctx = new VestalisEntities())
            {
                string xmlFormDefinitionInstance =
                    (from inspectionReportItem in ctx.InspectionReportItems
                     where inspectionReportItem.InspectionReportItemId == inspectionReportItemId
                     select inspectionReportItem.InspectionReport.XmlFormDefinitionInstance).FirstOrDefault();
                if (xmlFormDefinitionInstance != null)
                {
                    //Convert to a Form object
                    formReturn = XmlHelper.ReadFormFromXml<Form>(xmlFormDefinitionInstance);
                }
            }

            return formReturn;
        }
Пример #11
0
        /// <summary>
        /// Save the service order in the database
        /// </summary>
        /// <param name="formCollection">Values entered in the form</param>
        /// <param name="businessApplicationId">Business application identifier</param>
        /// <param name="userName">User name for auditing</param>
        public static void AddServiceOrder(FormCollection formCollection, Guid businessApplicationId, string userName)
        {
            //Get the fields definition for the business application
            Fields fieldBusinessApplication = CacheHandler.Get(String.Format("Field{0}", businessApplicationId),
                                            () => DynamicFormEngine.GetFields(businessApplicationId));

            Guid serviceOrderId = Guid.NewGuid();
            using (VestalisEntities ctx = new VestalisEntities())
            {
                IList<FormDefinition> businessFormDefinition =
                    (from formDefinition in ctx.FormDefinitions
                     where
                         formDefinition.BusinessApplicationId == businessApplicationId &&
                         formDefinition.IsDeleted == false
                     orderby formDefinition.FormOrder
                     select formDefinition).ToList();

                //Set the service Order information
                ServiceOrder serviceOrder = new ServiceOrder();
                SetServiceOrderToSave(businessApplicationId, serviceOrder, serviceOrderId, userName, businessFormDefinition);

                //Add the service order to the context
                ctx.ServiceOrders.AddObject(serviceOrder);

                foreach (var formDefinition in businessFormDefinition.Where(item => item.CatalogueValue.CatalogueValueData != FormType.ServiceOrder.ToString()).OrderBy(data => data.FormOrder))
                {
                    //Set the inspection report information
                    InspectionReport inspectionReport = new InspectionReport();
                    SetInspectionReportToSaveOrder(serviceOrderId, userName, inspectionReport, formDefinition);
                    //Add the inspection report to the context
                    ctx.InspectionReports.AddObject(inspectionReport);
                }

                //For each field form
                foreach (var formCollectionValue in formCollection.Keys)
                {
                    FillFormValue(ctx, serviceOrderId, userName, formCollection, formCollectionValue, fieldBusinessApplication);
                }
                ctx.SaveChanges();
            }
        }
Пример #12
0
        /// <summary>
        /// Delete selected orders
        /// </summary>
        /// <param name="selectedOrderIds">Ids of selected orders</param>
        /// <param name="userName">The name of the current user</param>
        public static void DeleteSelectedOrders(List<Guid> selectedOrderIds, string userName)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                var selectedOrders = (from serviceOrder in context.ServiceOrders
                                      where selectedOrderIds.Contains(serviceOrder.ServiceOrderId)
                                      select serviceOrder).ToList();

                if (selectedOrders != null && selectedOrders.Count > 0)
                {
                    selectedOrders.ForEach(serviceOrder =>
                    {
                        //Delete the record
                        serviceOrder.IsDeleted = true;
                        serviceOrder.ModificationBy = userName;
                        serviceOrder.ModificationDate = DateTime.UtcNow;
                        context.SaveChanges();
                    });
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Search the pictures for showing in the inspection report grid
        /// </summary>
        /// <param name="serviceOrderId">Service order id</param>
        /// <param name="inspectionReportItemId">Inspection report id</param>
        /// <returns>PictureGridModel</returns>
        public static PictureGridModel SearchPictureGridInspectionReport(Guid serviceOrderId, Guid inspectionReportItemId)
        {
            PictureGridModel result = new PictureGridModel();

            using (VestalisEntities context = new VestalisEntities())
            {
                //Retrieve the total number of pictures
                result.PictureCount = context.Pictures.Where(data => data.ServiceOrderId == serviceOrderId
                    && data.InspectionReportItemId == inspectionReportItemId && data.IsDeleted == false).Count();

                //Get the pictures in a specific page
                var tempResult = (from picture in context.Pictures
                                  where picture.ServiceOrderId == serviceOrderId && picture.IsDeleted == false
                                  && picture.InspectionReportItemId == inspectionReportItemId
                                  orderby picture.CreationDate
                                  select new { picture.PictureId, picture.PictureFile }).Take(3).ToList();

                //if exists data, the system makes the pagination
                if (tempResult != null)
                {
                    //set the paginated colletion
                    foreach (var tempPicture in tempResult)
                    {
                        PictureSearchModelItem pictureSearchModelItem = new PictureSearchModelItem();
                        pictureSearchModelItem.PictureId = tempPicture.PictureId;
                        Image pictureImage = ByteArrayToImage(tempPicture.PictureFile);
                        pictureSearchModelItem.SizeHeight = pictureImage.Height;
                        pictureSearchModelItem.SizeWidth = pictureImage.Width;
                        result.PictureList.Add(pictureSearchModelItem);
                    }
                }
            }

            return result;
        }
Пример #14
0
        /// <summary>
        /// Search the documents related to one service order
        /// </summary>
        /// <param name="serviceOrderId">Service order identifier</param>
        /// <param name="pageSize">Number of documents to retrieve</param>
        /// <param name="selectedPage">Page requested by the user</param>
        /// <param name="isClient">Flag to know if the user is the client</param>
        /// <returns>List of the documents</returns>
        public static DocumentSearchModel SearchDocuments(Guid serviceOrderId, int pageSize, int selectedPage, bool isClient = false)
        {
            DocumentSearchModel documentSearchModel = new DocumentSearchModel();
            List<Document> tempResult = null;
            int currentIndex = (selectedPage - 1) * pageSize;
            int countElements = 0;

            using (VestalisEntities ctx = new VestalisEntities())
            {
                //Retrieve the total number of pictures
                countElements = ctx.Documents.Where(data => data.ServiceOrderId == serviceOrderId && data.IsDeleted == false).Count();

                if (countElements > 0)
                {
                    //Get the pictures in a specific page
                    tempResult = (from document in ctx.Documents
                                  where document.ServiceOrderId == serviceOrderId && document.IsDeleted == false
                                  orderby document.CreationDate
                                  select document).Skip(currentIndex).Take(pageSize).ToList();
                }
                else
                {
                    //Get the pictures in a specific page
                    tempResult = (from document in ctx.Documents
                                  where document.ServiceOrderId == serviceOrderId && document.IsDeleted == false
                                  orderby document.CreationDate
                                  select document).ToList();
                }

                //if exists data, the system makes the pagination
                if (tempResult != null)
                {
                    //set the paginated colletion
                    documentSearchModel.DocumentList.Collection = tempResult;
                    //set the quantity of elements without pagination
                    documentSearchModel.DocumentList.TotalCount = countElements;
                    //set the number of pages
                    documentSearchModel.DocumentList.NumberOfPages = (int)Math.Ceiling((double)documentSearchModel.DocumentList.TotalCount / (double)pageSize);
                    //set the current page
                    documentSearchModel.DocumentList.Page = selectedPage;
                    //set the page size
                    documentSearchModel.DocumentList.PageSize = pageSize;
                }
            }

            documentSearchModel.Links = InspectionReportBusiness.GetInspectionReportLinks(serviceOrderId, isClient);
            return documentSearchModel;
        }
Пример #15
0
        /// <summary>
        /// Save a new or existing catalogue in the database
        /// </summary>
        /// <param name="file">File to be saved in the document</param>
        /// <param name="documentId">Document identifier</param>
        /// <param name="description">Document description</param>
        /// <param name="userName">Name of logged user</param>
        /// <param name="serviceOrderId">Service order idenfier</param>
        public static void SaveDocument(CuteWebUI.MvcUploadFile file, Guid? documentId, string description, string userName, Guid serviceOrderId)
        {
            Document documentNewEdit = null;
            using (VestalisEntities context = new VestalisEntities())
            {
                //if the entity don't have a catalogue id, the system will perform insert operation
                //otherwise, the system will perform edit operation
                if (documentId == Guid.Empty)
                {
                    documentNewEdit = new Document();
                    documentNewEdit.DocumentId = Guid.NewGuid();
                    documentNewEdit.ServiceOrderId = serviceOrderId;
                    //set auditory fields
                    documentNewEdit.CreationBy = userName;
                    documentNewEdit.CreationDate = DateTime.UtcNow;
                    documentNewEdit.DocumentDescription = description;
                    documentNewEdit.DocumentName = file.FileName;
                    //Copy the document to the entity
                    using (Stream fileStream = file.OpenStream())
                    {
                        byte[] buffer = new byte[fileStream.Length];
                        fileStream.Position = 0;
                        fileStream.Read(buffer, 0, (int)fileStream.Length);
                        documentNewEdit.DocumentFile = buffer;

                    }
                    context.Documents.AddObject(documentNewEdit);
                }
                else
                {
                    //get the current catalogue to edit
                    documentNewEdit = context.Documents
                    .FirstOrDefault(data => data.IsDeleted == false && data.DocumentId == documentId);

                    //set the description entered by the user
                    documentNewEdit.DocumentDescription = description;
                    //set auditory fields
                    documentNewEdit.ModificationBy = userName;
                    documentNewEdit.ModificationDate = DateTime.UtcNow;
                }

                //save changes
                context.SaveChanges();
            }
        }
Пример #16
0
 /// <summary>
 /// Get the document information to add or edit a document
 /// </summary>
 /// <param name="serviceOrderId">Service order identifier</param>
 /// <param name="documentId">Document identifier. It has value in edit mode; otherwise, it is null</param>
 /// <param name="isClient"></param>
 /// <returns></returns>
 public static DocumentModel GetNewEditDocument(Guid serviceOrderId, Guid? documentId, bool isClient = false)
 {
     DocumentModel documentModel = new DocumentModel();
     using (VestalisEntities ctx = new VestalisEntities())
     {
         //Get the document information when it is required for editing
         if (documentId.HasValue)
         {
             documentModel.Document =
             (from document in ctx.Documents
              where document.DocumentId == documentId
              select document).FirstOrDefault();
         }
     }
     documentModel.Links = InspectionReportBusiness.GetInspectionReportLinks(serviceOrderId, isClient);
     return documentModel;
 }
Пример #17
0
        /// <summary>
        /// Get catalogue query
        /// </summary>
        /// <param name="context">Vestalis context</param>
        /// <param name="formCollectionFiltered">Form collection</param>
        /// <param name="fieldName">Name of the field</param>
        /// <param name="tempQuery">Temporal query</param>
        /// <param name="query1Result">First query</param>
        /// <param name="isLikeSearch">Is or not a search with like statement</param>
        /// <returns>Object query of Guid</returns>
        private static ObjectQuery<Guid> GetCatalogueQuery(VestalisEntities context, Dictionary<string, string> formCollectionFiltered, string fieldName, ObjectQuery<Guid> tempQuery, ObjectQuery<Guid> query1Result, bool isLikeSearch)
        {
            Guid guidValue = Guid.Empty;
            string likeValue = string.Empty;
            string queryCatalogue = string.Empty;

            if (isLikeSearch)
            {
                likeValue = formCollectionFiltered[fieldName];
                queryCatalogue = "select VALUE FormValue.ServiceOrderId from VestalisEntities.FormValues as FormValue "
                                 + " inner join VestalisEntities.CatalogueValues as CatalogueValue on FormValue.CatalogueValueId = CatalogueValue.CatalogueValueId"
                                 + " where FormValue.IsDeleted = false"
                                 + " and FormValue.FieldName='" + fieldName + "' AND FormValue.InspectionReportItemId IS NULL"
                                 + " and CatalogueValue.CatalogueValueData like '%" + likeValue + "%' and CatalogueValue.IsDeleted = false";
            }
            else
            {
                guidValue = new Guid(formCollectionFiltered[fieldName]);
                queryCatalogue = "select VALUE FormValue.ServiceOrderId from VestalisEntities.FormValues as FormValue where FormValue.IsDeleted = false AND FormValue.CatalogueValueId =Guid '"
                               + guidValue.ToString() + "'  and FormValue.FieldName='" + fieldName + "' AND FormValue.InspectionReportItemId IS NULL";
            }

            ObjectQuery<Guid> objQueryGuid = new ObjectQuery<Guid>(queryCatalogue, context);

            if (tempQuery == null)
                tempQuery = query1Result.Intersect(objQueryGuid);
            else
                tempQuery = tempQuery.Intersect(objQueryGuid);
            return tempQuery;
        }
Пример #18
0
        /// <summary>
        /// Save the picture in the database
        /// </summary>
        /// <param name="file">File uploaded by the user</param>
        /// <param name="userName">User name logged in the application</param>
        /// <param name="serviceOrderReportId">Service order identifier related</param>
        public static void UploadDocument(CuteWebUI.MvcUploadFile file, Guid serviceOrderReportId, string userName)
        {
            //Add the file to DB along with metadata
            using (VestalisEntities context = new VestalisEntities())
            {
                //Create a new picture
                Picture picture = new Picture();
                picture.PictureId = Guid.NewGuid();
                picture.ServiceOrderId = serviceOrderReportId;
                //Copy the document to the entity
                using (Stream fileStream = file.OpenStream())
                {
                    byte[] buffer = new byte[fileStream.Length];
                    fileStream.Position = 0;
                    fileStream.Read(buffer, 0, (int)fileStream.Length);
                    picture.PictureFile = buffer;

                }
                picture.CreationBy = userName;
                picture.CreationDate = DateTime.UtcNow;
                context.Pictures.AddObject(picture);
                context.SaveChanges();
            }
        }
Пример #19
0
        /// <summary>
        /// Update service order values
        /// </summary>
        /// <param name="formCollection">Service order values</param>
        /// <param name="ctx">Context</param>
        /// <param name="serviceOrderId">Service order identifier</param>
        /// <param name="userName">User that modifies the information</param>
        /// <param name="formCollectionValue"></param>
        /// <param name="fieldBusinessApplication"></param>
        private static void FillFormValuesEdit(FormCollection formCollection, VestalisEntities ctx, Guid serviceOrderId, string userName, object formCollectionValue, Fields fieldBusinessApplication)
        {
            string fieldName;
            string valData;
            fieldName = formCollectionValue.ToString();
            ValueProviderResult val = formCollection.GetValue(fieldName);
            //Get the form value of the service order according the field name
            FormValue formValueToEdit = (from formValues in ctx.FormValues
                                         where
                                             formValues.ServiceOrderId == serviceOrderId &&
                                             formValues.IsDeleted == false &&
                                             formValues.FieldName == fieldName
                                         select formValues).FirstOrDefault();

            if (val != null)
            {
                //Get the form value for the specific field
                valData = val.AttemptedValue.ToString();

                if (!String.IsNullOrEmpty(valData))
                {
                    if (formValueToEdit != null)
                    {
                        SetFormValueToEditOrder(formValueToEdit, valData, userName);
                    }
                    else
                    {
                        //Set the form value
                        FormValue formValue = SetFormValueToSaveOrder(serviceOrderId, userName, fieldName,
                                                                      valData,
                                                                      fieldBusinessApplication);
                        //Add the form value to the context
                        ctx.FormValues.AddObject(formValue);
                    }
                }
                //Case this field had a value in the past, but the user has updated now without value
                else if (formValueToEdit != null)
                {
                    formValueToEdit.IsDeleted = true;
                    formValueToEdit.ModificationBy = userName;
                    formValueToEdit.ModificationDate = DateTime.UtcNow;
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Get the approbal items of the service order
        /// </summary>
        /// <param name="serviceOrderId">Id of service order</param>
        /// <param name="rolesForUser">List of roles</param>
        /// <param name="context">Data base context</param>
        /// <returns></returns>
        private static List<ApprovalItem> GetApprovalItemsOfServiceOrder(Guid serviceOrderId, List<string> rolesForUser, VestalisEntities context)
        {
            List<ApprovalItem> approvalItems = null;

            approvalItems = (from serviceOrder in context.ServiceOrders
                             join inspectionReport in context.InspectionReports on serviceOrder.ServiceOrderId equals inspectionReport.ServiceOrderId
                             join inspectionReportItem in context.InspectionReportItems on inspectionReport.InspectionReportId equals inspectionReportItem.InspectionReportId
                             join appItem in context.ApprovalItems on inspectionReportItem.InspectionReportItemId equals appItem.InspectionReportItemId
                             where serviceOrder.IsDeleted == false && inspectionReport.IsDeleted == false && inspectionReportItem.IsDeleted == false
                             && appItem.IsDeleted == false && serviceOrder.ServiceOrderId == serviceOrderId
                              && appItem.ApprovalStatus == (int)ApprovalStatus.Ready
                             && rolesForUser.Contains(appItem.RoleName)
                             select appItem).ToList();
            return approvalItems;
        }
Пример #21
0
        /// <summary>
        /// Get multi line query
        /// </summary>
        /// <param name="context">Vestalis context</param>
        /// <param name="formCollectionFiltered">Form collection</param>
        /// <param name="fieldName">Name of the field</param>
        /// <param name="tempQuery">Temporal query</param>
        /// <param name="query1Result">First query</param>
        /// <param name="isLikeSearch">Is or not a search with like statement</param>
        /// <returns>Object query of Guid</returns>
        private static ObjectQuery<Guid> GetMultiLineQuery(VestalisEntities context, Dictionary<string, string> formCollectionFiltered, string fieldName, ObjectQuery<Guid> tempQuery, ObjectQuery<Guid> query1Result, bool isLikeSearch)
        {
            string multilineValue = formCollectionFiltered[fieldName];
            string queryMultiText = string.Empty;

            if (isLikeSearch)
            {
                queryMultiText = "select VALUE FormValue.ServiceOrderId from VestalisEntities.FormValues as FormValue where  FormValue.IsDeleted = false AND FormValue.TextValue like '%"
                                        + multilineValue + "%'  and FormValue.FieldName='" + fieldName + "' AND FormValue.InspectionReportItemId IS NULL";

            }
            else
            {
                queryMultiText = "select VALUE FormValue.ServiceOrderId from VestalisEntities.FormValues as FormValue where  FormValue.IsDeleted = false AND FormValue.TextValue= '"
                                        + multilineValue + "'  and FormValue.FieldName='" + fieldName + "' AND FormValue.InspectionReportItemId IS NULL";
            }

            ObjectQuery<Guid> objQueryMultiText = new ObjectQuery<Guid>(queryMultiText, context);

            if (tempQuery == null)
                tempQuery = query1Result.Intersect(objQueryMultiText);
            else
                tempQuery = tempQuery.Intersect(objQueryMultiText);
            return tempQuery;
        }
Пример #22
0
        /// <summary>
        /// Get integer query
        /// </summary>
        /// <param name="context">Vestalis context</param>
        /// <param name="formCollectionFiltered">Form collection</param>
        /// <param name="fieldName">Name of the field</param>
        /// <param name="tempQuery">Temporal query</param>
        /// <param name="query1Result">First query</param>
        /// <returns>Object query of Guid</returns>s
        private static ObjectQuery<Guid> GetIntegerQuery(VestalisEntities context, Dictionary<string, string> formCollectionFiltered, string fieldName, ObjectQuery<Guid> tempQuery, ObjectQuery<Guid> query1Result)
        {
            int intValue = int.Parse(formCollectionFiltered[fieldName]);

            string queryInteger = "select VALUE FormValue.ServiceOrderId from VestalisEntities.FormValues as FormValue where FormValue.IsDeleted = false AND FormValue.IntegerValue= "
                                  + intValue.ToString() + "  and FormValue.FieldName='" + fieldName + "' AND FormValue.InspectionReportItemId IS NULL";
            ObjectQuery<Guid> objQueryInteger = new ObjectQuery<Guid>(queryInteger, context);

            if (tempQuery == null)
                tempQuery = query1Result.Intersect(objQueryInteger);
            else
                tempQuery = tempQuery.Intersect(objQueryInteger);
            return tempQuery;
        }
Пример #23
0
        /// <summary>
        /// Get date range query
        /// </summary>
        /// <param name="context">Vestalis context</param>
        /// <param name="formCollectionFiltered">Form collection</param>
        /// <param name="tempQuery">Temporal query</param>
        /// <param name="query1Result">First query</param>
        /// <returns>Object query of Guid</returns>
        private static ObjectQuery<Guid> GetDateRangeQuery(VestalisEntities context, Dictionary<string, string> formCollectionFiltered, ObjectQuery<Guid> tempQuery, ObjectQuery<Guid> query1Result)
        {
            string[] OrderDatefromValue = formCollectionFiltered.First(keyPair => keyPair.Key.EndsWith("from")).Value.Split(new char[] { '/', '-' }, StringSplitOptions.RemoveEmptyEntries);
            string[] OrderDateToValue = formCollectionFiltered.First(keyPair => keyPair.Key.EndsWith("to")).Value.Split(new char[] { '/', '-' }, StringSplitOptions.RemoveEmptyEntries);
            string fieldName = formCollectionFiltered.First(keyPair => keyPair.Key.EndsWith("to")).Key;
            fieldName = fieldName.Remove(fieldName.Length - 2, 2);

            DateTime OrderDatefrom = new DateTime(int.Parse(OrderDatefromValue[2]), int.Parse(OrderDatefromValue[1]), int.Parse(OrderDatefromValue[0]));
            DateTime OrderDateTo = new DateTime(int.Parse(OrderDateToValue[2]), int.Parse(OrderDateToValue[1]), int.Parse(OrderDateToValue[0]));

            OrderDatefrom = OrderDatefrom.Date;
            OrderDateTo = OrderDateTo.Date.AddDays(1).AddSeconds(-1);

            string queryDate = "select VALUE FormValue.ServiceOrderId from VestalisEntities.FormValues as FormValue where FormValue.IsDeleted = false and FormValue.DateValue >= DATETIME '"
                               + OrderDatefrom.ToString("yyyy-MM-dd HH:mm:ss.fffffff") + "' and FormValue.DateValue <= DATETIME '" + OrderDateTo.ToString("yyyy-MM-dd HH:mm:ss.fffffff")
                               + "' and FormValue.FieldName='" + fieldName + "' AND FormValue.InspectionReportItemId IS NULL";
            ObjectQuery<Guid> objQueryDate = new ObjectQuery<Guid>(queryDate, context);

            if (tempQuery == null)
                tempQuery = query1Result.Intersect(objQueryDate);
            else
                tempQuery = tempQuery.Intersect(objQueryDate);
            return tempQuery;
        }
Пример #24
0
        /// <summary>
        /// Search the pictures
        /// </summary>
        /// <param name="serviceOrderId">Service order identifier</param>
        /// <param name="inspectionReportItemId">Id of inspection report</param>
        /// <param name="rowSize">Row size</param>
        /// <returns>Picture results</returns>
        public static List<RowPictureCollection> SearchPicturesInspectionReport(Guid serviceOrderId, int rowSize, Guid inspectionReportItemId)
        {
            List<RowPictureCollection> result = new List<RowPictureCollection>();

            using (VestalisEntities ctx = new VestalisEntities())
            {

                //Get the pictures in a specific page
                var tempResult = (from picture in ctx.Pictures
                                  where picture.ServiceOrderId == serviceOrderId && picture.IsDeleted == false
                                  && picture.InspectionReportItemId == inspectionReportItemId
                                  orderby picture.CreationDate
                                  select new { picture.PictureId, picture.PictureFile }).ToList();

                //if exists data, the system makes the pagination
                if (tempResult != null)
                {
                    int rowsCount = (int)Math.Ceiling((double)tempResult.Count / (double)rowSize);

                    for (int i = 0; i < rowsCount; i++)
                    {
                        int currentIndex = i * rowSize;
                        RowPictureCollection currentRow = new RowPictureCollection();
                        currentRow.RowIdentifier = i + 1;
                        //set the paginated colletion
                        foreach (var tempPicture in tempResult.Skip(currentIndex).Take(rowSize))
                        {
                            PictureSearchModelItem pictureSearchModelItem = new PictureSearchModelItem();
                            pictureSearchModelItem.PictureId = tempPicture.PictureId;
                            Image pictureImage = ByteArrayToImage(tempPicture.PictureFile);
                            pictureSearchModelItem.SizeHeight = pictureImage.Height;
                            pictureSearchModelItem.SizeWidth = pictureImage.Width;
                            currentRow.PictureCollection.Add(pictureSearchModelItem);
                        }
                        result.Add(currentRow);
                    }

                }
            }

            return result;
        }
Пример #25
0
 /// <summary>
 /// Save the values entered in the service order
 /// </summary>
 /// <param name="ctx">EF context</param>
 /// <param name="serviceOrderId">Service order identifier</param>
 /// <param name="userName">User creator</param>
 /// <param name="formCollection"></param>
 /// <param name="formCollectionValue"></param>
 /// <param name="fieldBusinessApplication"></param>
 private static void FillFormValue(VestalisEntities ctx, Guid serviceOrderId, string userName, FormCollection formCollection, object formCollectionValue, Fields fieldBusinessApplication)
 {
     string fieldName;
     string valData;
     fieldName = formCollectionValue.ToString();
     ValueProviderResult val = formCollection.GetValue(fieldName);
     if (val != null)
     {
         //Get the form value for the specific field
         valData = val.AttemptedValue.ToString();
         if (!String.IsNullOrEmpty(valData))
         {
             //Set the form value
             FormValue formValue = SetFormValueToSaveOrder(serviceOrderId, userName, fieldName, valData,
                                                           fieldBusinessApplication);
             //Add the form value to the context
             ctx.FormValues.AddObject(formValue);
         }
     }
 }
Пример #26
0
 /// <summary>
 /// Get the xml file from the database of a specific type and load into a Form object
 /// </summary>
 /// <param name="businessApplicationId">Busines application id</param>
 /// <param name="formType">Form type</param>
 /// <param name="isClient">Flag to filter the client's reports</param>
 /// <returns>The Form definition for a specific type</returns>
 public static Form GetFormDefinition(Guid businessApplicationId, FormType formType, bool isClient)
 {
     Form formReturn = null;
     FormDefinition formDefinitionProcess = null;
     using (VestalisEntities ctx = new VestalisEntities())
     {
         //Form type code
         string formTypeText = formType.ToString();
         if (isClient)
         {
             //Execute search in the database to get the form definition according a type
             formDefinitionProcess = (from formDefinition in ctx.FormDefinitions
                                      where formDefinition.BusinessApplicationId == businessApplicationId
                                            && formDefinition.CatalogueValue.CatalogueValueData == formTypeText
                                            && formDefinition.IsClientVisible == isClient
                                      select formDefinition).FirstOrDefault();
         }
         else
         {
             //Execute search in the database to get the form definition according a type
             formDefinitionProcess = (from formDefinition in ctx.FormDefinitions
                                      where formDefinition.BusinessApplicationId == businessApplicationId
                                            && formDefinition.CatalogueValue.CatalogueValueData == formTypeText
                                      select formDefinition).FirstOrDefault();
         }
         if (formDefinitionProcess != null)
         {
             //Convert to a Form object
             formReturn = XmlHelper.ReadFormFromXml<Form>(formDefinitionProcess.XmlFormDefinition);
         }
         return formReturn;
     }
 }
Пример #27
0
 /// <summary>
 /// Save the picture in the database
 /// </summary>
 /// <param name="file">File uploaded by the user</param>
 /// <param name="userName">User name logged in the application</param>
 /// <param name="serviceOrderReportId">Service order identifier related</param>
 /// <param name="inspectionReportItemId">Id of inspections report item</param>
 public static void UploadPicture(CuteWebUI.MvcUploadFile file, Guid serviceOrderReportId, string userName, Guid? inspectionReportItemId = null)
 {
     //Add the file to DB along with metadata
     using (VestalisEntities context = new VestalisEntities())
     {
         //Create a new picture
         Picture picture = new Picture();
         picture.PictureId = Guid.NewGuid();
         picture.ServiceOrderId = serviceOrderReportId;
         if (inspectionReportItemId.HasValue)
             picture.InspectionReportItemId = inspectionReportItemId;
         //Copy document to entity
         using (Stream fileStream = file.OpenStream())
         {
             byte[] buffer = new byte[fileStream.Length];
             fileStream.Position = 0;
             fileStream.Read(buffer, 0, (int)fileStream.Length);
             picture.PictureFile = buffer;
             //Resize the thumbnail picture
             Image imageInput = Image.FromStream(fileStream);
             Image thumbnailImage = ResizeImage(imageInput, new Size(200, 200));
             ImageConverter converter = new ImageConverter();
             byte[] byteArrayThumb = (byte[])converter.ConvertTo(thumbnailImage, typeof(byte[]));
             //Set the thumbnail image to save in the database
             picture.PictureFileThumbnail = byteArrayThumb;
         }
         picture.CreationBy = userName;
         picture.CreationDate = DateTime.UtcNow;
         context.Pictures.AddObject(picture);
         //Save the new picture
         context.SaveChanges();
     }
 }
Пример #28
0
 /// <summary>
 /// Get the Picture according the identifier
 /// </summary>
 /// <param name="pictureId">Picture identifier</param>
 /// <returns>Picture data</returns>
 public static Picture GetDetailPicture(Guid pictureId)
 {
     using (VestalisEntities ctx = new VestalisEntities())
     {
         return (from picture in ctx.Pictures
                 where picture.PictureId == pictureId
                 select picture).FirstOrDefault();
     }
 }
Пример #29
0
        /// <summary>
        /// Delete all selected documents
        /// </summary>
        /// <param name="selectedIds">Ids of selected documents</param>
        /// <param name="userName">Name of the current user</param>
        public static void DeleteSelectedDocuments(List<Guid> selectedIds, string userName)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                var documentList = (from document in context.Documents
                                    where document.IsDeleted == false &
                                    selectedIds.Contains(document.DocumentId)
                                    select document).ToList();

                if (documentList != null && documentList.Count > 0)
                {
                    documentList.ForEach(documentToDelete =>
                    {
                        //Set the is_deleted flag as true
                        documentToDelete.IsDeleted = true;
                        //Set the audit fields
                        documentToDelete.ModificationBy = userName;
                        documentToDelete.ModificationDate = DateTime.UtcNow;
                        context.SaveChanges();
                    });
                }
            }
        }
Пример #30
0
 /// <summary>
 /// Get the document information
 /// </summary>
 /// <param name="documentId">Document identifier</param>
 /// <returns>Document data</returns>
 public static Document GetDocumentDetail(Guid documentId)
 {
     using (VestalisEntities ctx = new VestalisEntities())
     {
         return (from document in ctx.Documents
                 where document.DocumentId == documentId
                 select document).FirstOrDefault();
     }
 }