示例#1
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;
        }
 /// <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>
        /// 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();
            }
        }
 /// <summary>
 /// Delete service order
 /// </summary>
 /// <param name="serviceOrderId">Service Order id</param>
 /// <param name="userName">User name</param>
 public static void DeleteServiceOrder(Guid serviceOrderId, string userName)
 {
     using (VestalisEntities ctx = new VestalisEntities())
     {
         //Get the service order
         ServiceOrder serviceOrder =
             (from serviceOrderQuery in ctx.ServiceOrders
              where serviceOrderQuery.ServiceOrderId == serviceOrderId
              select serviceOrderQuery).FirstOrDefault();
         if (serviceOrder != null)
         {
             //Delete the record
             serviceOrder.IsDeleted = true;
             serviceOrder.ModificationBy = userName;
             serviceOrder.ModificationDate = DateTime.UtcNow;
             ctx.SaveChanges();
         }
     }
 }
        private static void EditApprovalItem(ParameterSaveInspectionReport parameters)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                InspectionReportItem inspectionReportItem = context.InspectionReportItems.FirstOrDefault(data => data.InspectionReportItemId == parameters.InspectionReportItemId);
                List<ValidationRole> roles = null;
                ValidationRole userRole = null;
                List<ApprovalItem> approvalItems = null;
                ApprovalItem approvalItem = null;
                bool isRole1Completed = false;

                if (inspectionReportItem != null)
                {
                    int currentApprovalLevel = inspectionReportItem.CurrentCompletedLevel.GetValueOrDefault();

                    userRole = (from role in context.ValidationRoles
                                where role.BusinessApplicationId == parameters.BusinessApplicationId
                                && role.IsDeleted == false && parameters.RolesForUser.Contains(role.RoleName)
                                select role).FirstOrDefault();

                    if (userRole.RoleLevel == 1)
                    {

                        roles = (from role in context.ValidationRoles
                                 where role.BusinessApplicationId == parameters.BusinessApplicationId
                                 && role.IsDeleted == false
                                 orderby role.RoleLevel
                                 select role).ToList();

                        approvalItems = (from appItems in context.ApprovalItems
                                         where appItems.InspectionReportItemId == parameters.InspectionReportItemId
                                         && appItems.IsDeleted == false
                                         select appItems).ToList();

                    }
                    else
                    {
                        roles = (from role in context.ValidationRoles
                                 where role.BusinessApplicationId == parameters.BusinessApplicationId
                                 && role.IsDeleted == false && role.RoleLevel >= currentApprovalLevel
                                 orderby role.RoleLevel
                                 select role).ToList();

                        approvalItems = (from appItems in context.ApprovalItems
                                         where appItems.InspectionReportItemId == parameters.InspectionReportItemId
                                         && appItems.IsDeleted == false && appItems.ApprovalLevel >= currentApprovalLevel
                                         select appItems).ToList();

                    }

                    foreach (ApprovalItem appItem in approvalItems)
                    {
                        appItem.IsDeleted = true;
                        appItem.ModificationBy = parameters.UserName;
                        appItem.ModificationDate = DateTime.UtcNow;
                    }

                    foreach (ValidationRole role in roles)
                    {
                        approvalItem = new ApprovalItem
                        {
                            ApprovalLevel = role.RoleLevel,
                            CanPublish = role.CanPublish,
                            CreationBy = parameters.UserName,
                            CreationDate = DateTime.UtcNow,
                            InspectionReportItemId = parameters.InspectionReportItemId,
                            IsReadOnly = role.IsReadOnly,
                            RoleName = role.RoleName,
                            ApprovalStatus = (int)ApprovalStatus.Waiting
                        };
                        if (role.RoleLevel == 1)
                        {
                            if (!role.CanPublish.GetValueOrDefault())
                            {
                                approvalItem.ApprovalStatus = (int)ApprovalStatus.Completed;
                                inspectionReportItem.CurrentCompletedLevel = 1;
                                inspectionReportItem.ModificationBy = parameters.UserName;
                                inspectionReportItem.ModificationDate = DateTime.UtcNow;
                                isRole1Completed = true;
                            }
                            else
                            {
                                approvalItem.ApprovalStatus = (int)ApprovalStatus.Ready;
                                isRole1Completed = false;
                            }

                        }
                        else if (isRole1Completed && role.RoleLevel == 2)
                        {
                            approvalItem.ApprovalStatus = (int)ApprovalStatus.Ready;
                        }
                        else if (role.RoleLevel == currentApprovalLevel)
                        {
                            approvalItem.ApprovalStatus = (int)ApprovalStatus.Ready;
                            inspectionReportItem.CurrentCompletedLevel = (currentApprovalLevel - 1);
                            inspectionReportItem.ModificationBy = parameters.UserName;
                            inspectionReportItem.ModificationDate = DateTime.UtcNow;
                        }
                        context.ApprovalItems.AddObject(approvalItem);
                    }
                }
                context.SaveChanges();
            }
        }
        public static void UnPublishInspectionReport(Guid inspectionReportItemId, string userName, List<string> userRoles)
        {
            using (VestalisEntities context = new VestalisEntities())
            {

                //Get approval item that have can publish equals true and approval status completed for the roles of the logged user
                ApprovalItem currentAppItem = (from appItem in context.ApprovalItems
                                               where
                                                   appItem.IsDeleted == false &&
                                                   userRoles.Contains(appItem.RoleName)
                                                   && appItem.InspectionReportItemId == inspectionReportItemId
                                                   && appItem.CanPublish == true &&
                                                   appItem.ApprovalStatus == (int)ApprovalStatus.Completed
                                               select appItem).FirstOrDefault();

                if (currentAppItem != null)
                {
                    //if the current inspection report item was published && and get the approval status completed, the system continue with the process
                    if (currentAppItem.InspectionReportItem.PublicationDate != null &&
                        currentAppItem.ApprovalStatus == (int)ApprovalStatus.Completed)
                    {
                        currentAppItem.IsDeleted = true;
                        currentAppItem.ModificationBy = userName;
                        currentAppItem.ModificationDate = DateTime.UtcNow;

                        ApprovalItem newAppItem = new ApprovalItem
                                                      {
                                                          InspectionReportItemId = inspectionReportItemId,
                                                          RoleName = currentAppItem.RoleName,
                                                          ApprovalLevel = currentAppItem.ApprovalLevel,
                                                          CanPublish = currentAppItem.CanPublish,
                                                          IsReadOnly = currentAppItem.IsReadOnly,
                                                          ApprovalStatus = (int)ApprovalStatus.Ready,
                                                          CreationBy = userName,
                                                          CreationDate = DateTime.UtcNow
                                                      };
                        context.ApprovalItems.AddObject(newAppItem);

                        InspectionReportItem currentInspectionReportItem =
                            (from inspectionReportItem in context.InspectionReportItems
                             where inspectionReportItem.InspectionReportItemId == inspectionReportItemId
                             select inspectionReportItem).FirstOrDefault();

                        if (currentInspectionReportItem != null)
                        {
                            currentInspectionReportItem.ModificationBy = userName;
                            currentInspectionReportItem.ModificationDate = DateTime.UtcNow;
                            currentInspectionReportItem.PublicationDate = null;
                            currentInspectionReportItem.CurrentCompletedLevel -= 1;
                        }

                    }
                }
                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
 private static void UpdateCatalogValue(CatalogueValueModel model, string userName, VestalisEntities context, bool existCatalogueValue)
 {
     //get the current catalogue
     CatalogueValue catalogueValueModified = context.CatalogueValues.FirstOrDefault(data => data.IsDeleted == false && data.CatalogueValueId == model.CatalogValId);
     //if the current catalogue is not null, the system continues with the process
     if (catalogueValueModified != null && catalogueValueModified.CatalogueValueData == model.CatalogValData)
     {
         //set the fields to update the information
         catalogueValueModified.CatalogueValueData = model.CatalogValData;
         catalogueValueModified.CatalogueValueDescription = model.CatalogDesc;
         //set auditory fields
         catalogueValueModified.ModificationBy = userName;
         catalogueValueModified.ModificationDate = DateTime.UtcNow;
         //save all changes
         context.SaveChanges();
     }
     else if (catalogueValueModified != null && catalogueValueModified.CatalogueValueData != model.CatalogValData)
     {
         if (!existCatalogueValue)
         {
             //set the fields to update the information
             catalogueValueModified.CatalogueValueData = model.CatalogValData;
             catalogueValueModified.CatalogueValueDescription = model.CatalogDesc;
             //set auditory fields
             catalogueValueModified.ModificationBy = userName;
             catalogueValueModified.ModificationDate = DateTime.UtcNow;
             //save all changes
             context.SaveChanges();
         }
         else
         {
             model.Errors.Add(LanguageResource.CatalogueValueExists);
         }
     }
 }
        /// <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();
            }
        }
示例#11
0
        /// <summary>
        /// Publish or validate all inspection reports for one service order
        /// </summary>
        /// <param name="serviceOrderId">Id of service order</param>
        /// <param name="rolesForUser">Roles assigned for the logged user</param>
        /// <param name="userName">The name of logged user</param>
        public static void PublishValidateAllInspectionReports(Guid serviceOrderId, List<string> rolesForUser, string userName)
        {
            List<ApprovalItem> approvalItems = null;
            int approvalLevel = 0;
            Guid inspectionReportItemId = Guid.Empty;

            using (VestalisEntities context = new VestalisEntities())
            {

                approvalItems = GetApprovalItemsOfServiceOrder(serviceOrderId, rolesForUser, context);

                foreach (ApprovalItem approvalItem in approvalItems)
                {
                    approvalLevel = 0;
                    approvalLevel = approvalItem.ApprovalLevel;
                    approvalItem.ApprovalStatus = (int)ApprovalStatus.Completed;
                    approvalItem.ModificationBy = userName;
                    approvalItem.ModificationDate = DateTime.UtcNow;

                    inspectionReportItemId = approvalItem.InspectionReportItemId.GetValueOrDefault();

                    //Get the next approval item
                    ApprovalItem approvalItem2 = (from appItem in context.ApprovalItems
                                                  where appItem.InspectionReportItemId == inspectionReportItemId
                                                          && appItem.IsDeleted == false
                                                          && appItem.ApprovalStatus == (int)ApprovalStatus.Waiting
                                                          && appItem.ApprovalLevel == (approvalLevel + 1)
                                                  select appItem).FirstOrDefault();

                    //if exist, update the status
                    if (approvalItem2 != null)
                    {
                        approvalItem2.ApprovalStatus = (int)ApprovalStatus.Ready;
                        approvalItem2.ModificationBy = userName;
                        approvalItem2.ModificationDate = DateTime.UtcNow;
                    }

                    //update the inspection report item with the current completed level
                    InspectionReportItem currentInspectionReportItem = (from inspectionReportItem in context.InspectionReportItems
                                                                        where inspectionReportItem.InspectionReportItemId == inspectionReportItemId
                                                                        select inspectionReportItem).FirstOrDefault();

                    currentInspectionReportItem.CurrentCompletedLevel = approvalLevel;
                    currentInspectionReportItem.ModificationBy = userName;
                    currentInspectionReportItem.ModificationDate = DateTime.UtcNow;
                    if (approvalItem.CanPublish.GetValueOrDefault())
                    {
                        currentInspectionReportItem.PublicationDate = DateTime.UtcNow;
                    }
                }

                //save all changes
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Save the service order in the database
        /// </summary>
        /// <param name="parameters">Inspection report parameters</param>
        public static void EditInspectionReport(ParameterSaveInspectionReport parameters)
        {
            IList<string> keyNames = new List<string>();
            //Get the fields definition for the business application
            Fields fieldBusinessApplication = CacheHandler.Get(String.Format("Field{0}", parameters.BusinessApplicationId),
                                            () => DynamicFormEngine.GetFields(parameters.BusinessApplicationId));

            using (VestalisEntities context = new VestalisEntities())
            {
                //Get the form values inserted in the database but they aren't in formCollection.Keys
                foreach (var formCollectionValue in parameters.FormCollection.Keys)
                {
                    keyNames.Add(formCollectionValue.ToString());
                }

                var formsNotSent = (from formValues in context.FormValues
                                    where
                                        formValues.ServiceOrderId == parameters.ServiceOrderId &&
                                        formValues.InspectionReportItemId == parameters.InspectionReportItemId &&
                                        formValues.IsDeleted == false &&
                                        !keyNames.Contains(formValues.FieldName)
                                    select formValues);

                foreach (var formNotSent in formsNotSent)
                {
                    formNotSent.IsDeleted = true;
                    formNotSent.ModificationBy = parameters.UserName;
                    formNotSent.ModificationDate = DateTime.UtcNow;
                }

                //For each field form
                foreach (var formCollectionValue in parameters.FormCollection.Keys)
                {
                    SetFieldValuesEditInspection(parameters, context, formCollectionValue, fieldBusinessApplication);
                }
                context.SaveChanges();
            }

            EditApprovalItem(parameters);
        }
        /// <summary>
        /// Delete all selected report items 
        /// </summary>
        /// <param name="selectedIds">Ids of selected report items</param>
        /// <param name="userName">The name of the current user</param>
        public static void DeleteSelectedInspectionReports(List<Guid> selectedIds,string userName)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                var selectedReportItems = (from inspectionReportItem in context.InspectionReportItems
                                           where selectedIds.Contains(inspectionReportItem.InspectionReportItemId)
                                           select inspectionReportItem).ToList();

                if (selectedReportItems != null && selectedReportItems.Count > 0)
                {
                    selectedReportItems.ForEach(inspectionReportItem =>
                    {
                        //Delete the record
                        inspectionReportItem.IsDeleted = true;
                        inspectionReportItem.ModificationBy = userName;
                        inspectionReportItem.ModificationDate = DateTime.UtcNow;
                        context.SaveChanges();
                    });
                }
            }
        }
        /// <summary>
        /// Perform the update operaton when a permission is updated
        /// </summary>
        /// <param name="model">User model</param>
        /// <param name="loggedUser">Logged user</param>
        /// <param name="context">Database context</param>
        /// <param name="exists">Exist or not exist the user</param>
        private static void UpdateBusinessApplicationUser(UserModel model, string loggedUser, VestalisEntities context, bool exists)
        {
            VestalisUserApplication userApplication = (from userApp in context.VestalisUserApplications
                                                       where userApp.IsDeleted == false && userApp.UserName == model.Email
                                                       && userApp.BusinessApplicationId == model.BusinessApplicationId
                                                       select userApp).FirstOrDefault();

            if (userApplication != null && userApplication.BusinessApplicationId == model.BusinessApplicationIdPer)
            {
                userApplication.BusinessApplicationId = model.BusinessApplicationIdPer;
                userApplication.ClientId = model.ClientId;
                userApplication.ModificationBy = loggedUser;
                userApplication.CreationDate = DateTime.UtcNow;

                context.SaveChanges();
            }
            else if (userApplication != null && userApplication.BusinessApplicationId != model.BusinessApplicationIdPer)
            {
                if (!exists)
                {
                    userApplication.BusinessApplicationId = model.BusinessApplicationIdPer;
                    userApplication.ClientId = model.ClientId;
                    userApplication.ModificationBy = loggedUser;
                    userApplication.CreationDate = DateTime.UtcNow;

                    context.SaveChanges();
                }
                else
                {
                    model.ErrorList.Add(LanguageResource.UserInBusinessApplication);
                }
            }
        }
        /// <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);
                    }
                }
            }
        }
        /// <summary>
        /// Delete a user from the system
        /// </summary>
        /// <param name="userName">Selected user name for deleting</param>
        /// <param name="loggedUserName">Logged user name</param>
        public void DeleteUser(string userName, string loggedUserName)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                //Get the list of business application attached to the user
                var businessAppList = (from businessApp in context.VestalisUserApplications
                                       where businessApp.IsDeleted == false && businessApp.UserName == userName
                                       select businessApp).ToList();

                foreach (var item in businessAppList)
                {
                    //delete all business applications
                    item.IsDeleted = true;
                    item.ModificationBy = loggedUserName;
                    item.ModificationDate = DateTime.UtcNow;
                }

                //get all roles of the user
                var rolesFromUser = Roles.GetRolesForUser(userName);

                //remove the roles
                if (rolesFromUser.Length > 0)
                    Roles.RemoveUserFromRoles(userName, rolesFromUser);

                //delete user from membership table
                var memberships = (from user in context.aspnet_Users
                                   join membership in context.aspnet_Membership on user.UserId equals membership.UserId
                                   where user.UserName == userName
                                   select membership).ToList();
                foreach (var item in memberships)
                {
                    context.aspnet_Membership.DeleteObject(item);
                }

                //delete profiles of the user
                var profiles = (from user in context.aspnet_Users
                                join profile in context.aspnet_Profile on user.UserId equals profile.UserId
                                where user.UserName == userName
                                select profile).ToList();
                foreach (var item in profiles)
                {
                    context.aspnet_Profile.DeleteObject(item);
                }

                //delete the user
                var userToDelete = (from user in context.aspnet_Users
                                    where user.UserName == userName
                                    select user).ToList();
                foreach (var item in userToDelete)
                {
                    context.aspnet_Users.DeleteObject(item);
                }

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Verify and save VestalisUserApplications
        /// </summary>
        /// <param name="model">Model</param>
        /// <param name="loggedUser">Logged user</param>
        public static void VerifySaveVestalisUserApplications(UserModel model, string loggedUser)
        {
            using (VestalisEntities context = new VestalisEntities())
            {
                //if the selected business application is already added to the user, the system will show an error message
                //otherwise the system continues with the process
                bool exists = (from userApp in context.VestalisUserApplications
                               where userApp.IsDeleted == false && userApp.UserName == model.Email
                               && userApp.BusinessApplicationId == model.BusinessApplicationId
                               select userApp).Any();

                if (model.OpenMode == (int)ScreenOpenMode.Add)
                {
                    if (!exists)
                    {
                        VestalisUserApplication userApplication = new VestalisUserApplication
                        {
                            BusinessApplicationId = model.BusinessApplicationId,
                            UserName = model.Email,
                            ClientId = model.ClientId,
                            CreationBy = loggedUser,
                            CreationDate = DateTime.UtcNow
                        };

                        context.VestalisUserApplications.AddObject(userApplication);
                        context.SaveChanges();
                    }
                    else
                    {
                        model.ErrorList.Add(LanguageResource.UserInBusinessApplication);
                    }
                }
                else if (model.OpenMode == (int)ScreenOpenMode.Edit)
                {
                    UpdateBusinessApplicationUser(model, loggedUser, context, exists);

                }

            }
        }
示例#18
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;
        }
示例#19
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>
        /// <param name="serviceOrderId">Service order identifier</param>
        public static void EditServiceOrder(FormCollection formCollection, Guid businessApplicationId, string userName, Guid serviceOrderId)
        {
            IList<string> keyNames = new List<string>();
            //Get the fields definition for the business application
            Fields fieldBusinessApplication = CacheHandler.Get(String.Format("Field{0}", businessApplicationId),
                                            () => DynamicFormEngine.GetFields(businessApplicationId));

            using (VestalisEntities ctx = new VestalisEntities())
            {
                //Get the form values inserted in the database but they aren't in formCollection.Keys
                foreach (var formCollectionValue in formCollection.Keys)
                {
                    keyNames.Add(formCollectionValue.ToString());
                }

                var formsNotSent = (from formValues in ctx.FormValues
                                    where
                                        formValues.ServiceOrderId == serviceOrderId &&
                                        formValues.IsDeleted == false &&
                                        formValues.InspectionReportItemId == null &&
                                        !keyNames.Contains(formValues.FieldName)
                                    select formValues);

                foreach (var formNotSent in formsNotSent)
                {
                    formNotSent.IsDeleted = true;
                    formNotSent.ModificationBy = userName;
                    formNotSent.ModificationDate = DateTime.UtcNow;
                }

                //For each field form
                foreach (var formCollectionValue in formCollection.Keys)
                {
                    FillFormValuesEdit(formCollection, ctx, serviceOrderId, userName, formCollectionValue, fieldBusinessApplication);
                }
                ctx.SaveChanges();
            }
        }
        /// <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();
            }
        }
 /// <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();
     }
 }
示例#22
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();
                    });
                }
            }
        }
示例#23
0
        /// <summary>
        /// Save a new catalogue in the database
        /// </summary>
        /// <param name="model">Catalogue model</param>
        /// <param name="userName">Name of logged user</param>
        public static CatalogueModel SaveCategoryCatalogue(CatalogueModel model, string userName)
        {
            bool categoryExist = false;
            using (VestalisEntities context = new VestalisEntities())
            {

                categoryExist = context.Catalogues
                    .Any(data => data.IsDeleted == false && data.BusinessApplicationId == model.BusinessApplicationId
                        && data.CatalogueCategoryName == model.CatalogueCategoryName);

                //if the entity don't have a catalogue id, the system will perform insert operation
                //otherwise, the system will perform edit operation
                if (model.CatalogueId == Guid.Empty)
                {
                    if (!categoryExist)
                    {
                        Catalogue catalogue = new Catalogue
                        {
                            BusinessApplicationId = model.BusinessApplicationId,
                            CatalogueCategoryName = model.CatalogueCategoryName,
                        };
                        //set auditory fields
                        catalogue.CreationBy = userName;
                        catalogue.CreationDate = DateTime.UtcNow;
                        context.Catalogues.AddObject(catalogue);

                        //save changes
                        context.SaveChanges();
                        model.CatalogueId = catalogue.CatalogueId;
                    }
                    else
                    {
                        model.Errors.Add(LanguageResource.CatalogueCategoryExists);
                    }
                }
                else
                {
                    UpdateCatalogueCategory(model, userName, categoryExist, context);
                }

            }
            return model;
        }
        public static void PublishValidateInspectionReport(Guid inspectionReportItemId, string userName)
        {
            int approvalLevel = 0;
            using (VestalisEntities context = new VestalisEntities())
            {
                //get the current approval item
                ApprovalItem approvalItem = (from appItem in context.ApprovalItems
                                             where appItem.InspectionReportItemId == inspectionReportItemId
                                                    && appItem.IsDeleted == false
                                                    && appItem.ApprovalStatus == (int)ApprovalStatus.Ready
                                             select appItem).FirstOrDefault();

                //if exist, update the status
                if (approvalItem != null)
                {
                    approvalLevel = approvalItem.ApprovalLevel;
                    approvalItem.ApprovalStatus = (int)ApprovalStatus.Completed;
                    approvalItem.ModificationBy = userName;
                    approvalItem.ModificationDate = DateTime.UtcNow;

                    //Get the next approval item
                    ApprovalItem approvalItem2 = (from appItem in context.ApprovalItems
                                                  where appItem.InspectionReportItemId == inspectionReportItemId
                                                         && appItem.IsDeleted == false
                                                         && appItem.ApprovalStatus == (int)ApprovalStatus.Waiting
                                                         && appItem.ApprovalLevel == (approvalLevel + 1)
                                                  select appItem).FirstOrDefault();

                    //if exist, update the status
                    if (approvalItem2 != null)
                    {
                        approvalItem2.ApprovalStatus = (int)ApprovalStatus.Ready;
                        approvalItem2.ModificationBy = userName;
                        approvalItem2.ModificationDate = DateTime.UtcNow;
                    }

                    //update the inspection report item with the current completed level
                    InspectionReportItem currentInspectionReportItem = (from inspectionReportItem in context.InspectionReportItems
                                                                        where inspectionReportItem.InspectionReportItemId == inspectionReportItemId
                                                                        select inspectionReportItem).FirstOrDefault();

                    currentInspectionReportItem.CurrentCompletedLevel = approvalLevel;
                    currentInspectionReportItem.ModificationBy = userName;
                    currentInspectionReportItem.ModificationDate = DateTime.UtcNow;
                    if (approvalItem.CanPublish.GetValueOrDefault())
                    {
                        currentInspectionReportItem.PublicationDate = DateTime.UtcNow;
                    }

                    //save all changes
                    context.SaveChanges();
                }

            }
        }
示例#25
0
        private static void UpdateCatalogueCategory(CatalogueModel model, string userName, bool categoryExist, VestalisEntities context)
        {
            //get the current catalogue to edit
            Catalogue CatalogueModified = context.Catalogues
            .FirstOrDefault(data => data.IsDeleted == false && data.CatalogueId == model.CatalogueId);

            if (CatalogueModified != null && CatalogueModified.CatalogueCategoryName == model.CatalogueCategoryName)
            {
                //set fields to modify the information
                CatalogueModified.BusinessApplicationId = model.BusinessApplicationId;
                CatalogueModified.CatalogueCategoryName = model.CatalogueCategoryName;
                //set auditory fields
                CatalogueModified.ModificationBy = userName;
                CatalogueModified.ModificationDate = DateTime.UtcNow;
                //save changes
                context.SaveChanges();
            }
            else if (CatalogueModified != null && CatalogueModified.CatalogueCategoryName != model.CatalogueCategoryName)
            {
                if (!categoryExist)
                {
                    //set fields to modify the information
                    CatalogueModified.BusinessApplicationId = model.BusinessApplicationId;
                    CatalogueModified.CatalogueCategoryName = model.CatalogueCategoryName;
                    //set auditory fields
                    CatalogueModified.ModificationBy = userName;
                    CatalogueModified.ModificationDate = DateTime.UtcNow;
                    //save changes
                    context.SaveChanges();
                }
                else
                {
                    model.Errors.Add(LanguageResource.CatalogueCategoryExists);
                }
            }
        }
 /// <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();
     }
 }
        /// <summary>
        /// Validate or publish all inspection report items
        /// </summary>
        /// <param name="parameters">Parameters of PublishValidateSelected method</param>
        public static void PublishValidateSelected(ParameterPublishValidateInspectionReports parameters)
        {
            Guid inspectionReportId = GetInspectionReportByName(parameters.InspectionReportName, parameters.ServiceOrderId).InspectionReportId;
            List<ApprovalItem> approvalItems = null;
            int approvalLevel = 0;
            Guid inspectionReportItemId = Guid.Empty;
            using (VestalisEntities context = new VestalisEntities())
            {
                approvalItems = GetApprovalItems(context, parameters.RolesForUser,parameters.SelectedIds).Where(data => data.ApprovalStatus == (int)ApprovalStatus.Ready
                    && data.CanPublish == parameters.IsPublish).ToList();
                foreach (ApprovalItem approvalItem in approvalItems)
                {
                    approvalLevel = 0;
                    approvalLevel = approvalItem.ApprovalLevel;
                    approvalItem.ApprovalStatus = (int)ApprovalStatus.Completed;
                    approvalItem.ModificationBy = parameters.UserName;
                    approvalItem.ModificationDate = DateTime.UtcNow;

                    inspectionReportItemId = approvalItem.InspectionReportItemId.GetValueOrDefault();

                    //Get the next approval item
                    ApprovalItem approvalItem2 = (from appItem in context.ApprovalItems
                                                  where appItem.InspectionReportItemId == inspectionReportItemId
                                                         && appItem.IsDeleted == false
                                                         && appItem.ApprovalStatus == (int)ApprovalStatus.Waiting
                                                         && appItem.ApprovalLevel == (approvalLevel + 1)
                                                  select appItem).FirstOrDefault();

                    //if exist, update the status
                    if (approvalItem2 != null)
                    {
                        approvalItem2.ApprovalStatus = (int)ApprovalStatus.Ready;
                        approvalItem2.ModificationBy = parameters.UserName;
                        approvalItem2.ModificationDate = DateTime.UtcNow;
                    }

                    //update the inspection report item with the current completed level
                    InspectionReportItem currentInspectionReportItem = (from inspectionReportItem in context.InspectionReportItems
                                                                        where inspectionReportItem.InspectionReportItemId == inspectionReportItemId
                                                                        select inspectionReportItem).FirstOrDefault();

                    currentInspectionReportItem.CurrentCompletedLevel = approvalLevel;
                    currentInspectionReportItem.ModificationBy = parameters.UserName;
                    currentInspectionReportItem.ModificationDate = DateTime.UtcNow;
                    if (approvalItem.CanPublish.GetValueOrDefault())
                    {
                        currentInspectionReportItem.PublicationDate = DateTime.UtcNow;
                    }

                }
                //save all changes
                context.SaveChanges();
            }
        }
        /// <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();
                    });
                }
            }
        }
示例#29
0
        public static CatalogueValueModel SaveCatalogueValue(CatalogueValueModel model, string userName)
        {
            using (VestalisEntities context = new VestalisEntities())
            {

                bool existCatalogueValue = context.CatalogueValues.Any(data => data.IsDeleted == false
                        && data.CatalogueId == model.CatalogueId
                        && data.CatalogueValueData == model.CatalogValData);

                //if the CatalogueValueId is empty, the system will perform the insert operation
                //otherwise the system will perform the edit operation
                if (model.CatalogValId == null)
                {
                    //if the current catalogue is not exists, the system continues with the process
                    if (!existCatalogueValue)
                    {
                        CatalogueValue catalogueValue = new CatalogueValue();
                        catalogueValue.CatalogueValueData = model.CatalogValData;
                        catalogueValue.CatalogueValueDescription = model.CatalogDesc;
                        catalogueValue.CatalogueId = model.CatalogueId.GetValueOrDefault();
                        //set  auditory fields
                        catalogueValue.CreationBy = userName;
                        catalogueValue.CreationDate = DateTime.UtcNow;
                        //add the new object
                        context.CatalogueValues.AddObject(catalogueValue);
                        //save all changes
                        context.SaveChanges();
                    }
                    else
                    {
                        model.Errors.Add(LanguageResource.CatalogueValueExists);
                    }

                }
                else
                {
                    UpdateCatalogValue(model, userName, context, existCatalogueValue);
                }

                //Remove from the cache the catalogue
                Catalogue catalogue = GetCatalogueCategory(model.CatalogueId.GetValueOrDefault());
                CacheHandler.Remove(String.Format("{0}{1}", catalogue.CatalogueCategoryName, catalogue.BusinessApplicationId));

            }
            return model;
        }