//[Authorize(Roles = "DataTeam_APPS_RW, APP_ADMINS")]
        public ActionResult Delete(ExtPartMapping entry)
        {
            var context  = new Magnaflow_WebEntities();
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            Models.Response.Response response = null;

            /*
             * Do checks here making sure input is as expectied
             */

            try
            {
                var deleteEntry = context.ExtPartMappings.Where(x => x.Id == entry.Id).FirstOrDefault();

                if (deleteEntry != null)
                {
                    context.ExtPartMappings.Remove(deleteEntry);
                    context.SaveChanges();
                    response = new Models.Response.Response()
                    {
                        Success            = true,
                        JSON_RESPONSE_DATA = null // JsonConvert.SerializeObject(commissionDataResponseObject)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                    };
                    #region log activity
                    var logDelete = new ExtPartMappingToolStagingActivity()
                    {
                        Time       = DateTime.UtcNow,
                        UserId     = User.Identity.Name,
                        ActionType = Types.ActionType.DELETE
                    };
                    #endregion
                    context.ExtPartMappingToolStagingActivities.Add(logDelete);
                    context.SaveChanges();
                }
                else
                {
                    response = new Models.Response.Response()
                    {
                        Success            = false,
                        JSON_RESPONSE_DATA = null, // JsonConvert.SerializeObject(commissionDataResponseObject)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                        Message            = "Data submitted to delete does not exist."
                    };
                }
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }catch (Exception ex)
            {
                throw;//  new HttpException(404, "Internal error");
            }

            //return JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings); //Returns students list as JSON
        }
示例#2
0
        public static bool InitiateFiles(List <String> acesFileNames, List <String> piesFileNames, bool isStaging)
        {
            try
            {
                var context           = new Magnaflow_WebEntities();
                var processFilesBatch = new EPM_ProcessFilesBatch()
                {
                    StageId = isStaging? Models.Types.ProcessFilesStages.StagingInit: Models.Types.ProcessFilesStages.ProductionInit,
                    Active  = true
                };
                context.EPM_ProcessFilesBatch.Add(processFilesBatch);
                context.SaveChanges();

                foreach (var fileName in acesFileNames)
                {
                    if (!String.IsNullOrWhiteSpace(fileName))
                    {
                        var acesFile = new EPM_ProcessFilesDetail()
                        {
                            BatchId  = processFilesBatch.BatchId,
                            FileName = fileName
                        };
                        context.EPM_ProcessFilesDetail.Add(acesFile);
                    }
                }

                foreach (var fileName in piesFileNames)
                {
                    if (!String.IsNullOrWhiteSpace(fileName))
                    {
                        var piesFile = new EPM_ProcessFilesDetail()
                        {
                            BatchId  = processFilesBatch.BatchId,
                            FileName = fileName
                        };
                        context.EPM_ProcessFilesDetail.Add(piesFile);
                    }
                }
                context.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#3
0
        public static bool ClosePipeline(int batchId)
        {
            try
            {
                var context         = new Magnaflow_WebEntities();
                var activeFileBatch = context.EPM_ProcessFilesBatch.Where(x => x.BatchId == batchId).FirstOrDefault();

                if (activeFileBatch == null)
                {
                    return(false);
                }
                activeFileBatch.Active = false;
                context.SaveChanges();
            }
            catch (Exception ex)
            {
            }
            return(true);
        }
示例#4
0
        public static bool ProductionInit(int batchId)
        {
            try
            {
                var context         = new Magnaflow_WebEntities();
                var activeFileBatch = context.EPM_ProcessFilesBatch.Where(x => x.BatchId == batchId).FirstOrDefault();

                if (activeFileBatch == null)
                {
                    return(false);
                }
                activeFileBatch.StageId = Models.Types.ProcessFilesStages.ProductionInit;
                context.SaveChanges();
            }
            catch (Exception ex)
            {
            }
            return(true);
        }
示例#5
0
        public ActionResult Commit(List <ExtPartMappingToolUploadStaging> stagingList)
        {
            var context = new Magnaflow_WebEntities();

            Models.Response.Response response = null;
            try
            {
                foreach (var stagingRecord in stagingList)
                {
                    context.ExtPartMappings.Add(new ExtPartMapping()
                    {
                        OldPartId = stagingRecord.OldPartId,
                        NewPartId = stagingRecord.NewPartId
                    });
                }
                var logBeginUpload = new ExtPartMappingToolStagingActivity()
                {
                    Time       = DateTime.UtcNow,
                    UserId     = User.Identity.Name,
                    ActionType = Types.ActionType.COMMIT_UPLOAD
                };
                context.ExtPartMappingToolStagingActivities.Add(logBeginUpload);

                context.SaveChanges();

                response = new Models.Response.Response()
                {
                    Success            = true,
                    JSON_RESPONSE_DATA = null// JsonConvert.SerializeObject(stagingList)
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                response = new Models.Response.Response()
                {
                    Success            = false,
                    JSON_RESPONSE_DATA = JsonConvert.SerializeObject("Internal_Error")
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }
        }
        //[Authorize(Roles = "DataTeam_APPS_RW, APP_ADMINS")]
        public ActionResult Save(Models.Request.NestedViews.Save saveModel)
        {
            var context  = new Magnaflow_WebEntities();
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            Models.Response.Response response     = null;
            ExtPartMapping           extPartEntry = null;

            //Models.CommissionData commissionDataResponseObject = null;

            /*
             * get rid of non alphanumeric and spaces [^a-zA-Z0-9]
             */



            if (saveModel.Id != null)
            {
                extPartEntry = context.ExtPartMappings.Where(x => x.Id == saveModel.Id).FirstOrDefault();
                if (extPartEntry == null)
                {
                    response = new Models.Response.Response()
                    {
                        Success            = false,
                        JSON_RESPONSE_DATA = null, //JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                        Message            = "Data to edit does not exist."
                    };
                    return(this.Json(response, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    extPartEntry.OldPartId = saveModel.OldPartId;
                    extPartEntry.NewPartId = saveModel.NewPartId;
                    context.SaveChanges();
                    #region log save
                    var logUpdate = new ExtPartMappingToolStagingActivity()
                    {
                        Time       = DateTime.UtcNow,
                        UserId     = User.Identity.Name,
                        ActionType = Types.ActionType.UPDATE
                    };
                    context.ExtPartMappingToolStagingActivities.Add(logUpdate);
                    context.SaveChanges();
                    #endregion

                    response = new Models.Response.Response()
                    {
                        Success            = true,
                        JSON_RESPONSE_DATA = JsonConvert.SerializeObject(extPartEntry)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                    };
                    return(this.Json(response, JsonRequestBehavior.AllowGet));
                }
            }
            else //if it's null we're adding
            {
                extPartEntry = new ExtPartMapping()
                {
                    OldPartId = saveModel.OldPartId,
                    NewPartId = saveModel.NewPartId
                };

                context.ExtPartMappings.Add(extPartEntry);
                context.SaveChanges();

                /* Here needs to be an updatae model of the extpartmapping added object */
                #region log save
                var logSave = new ExtPartMappingToolStagingActivity()
                {
                    Time       = DateTime.UtcNow,
                    UserId     = User.Identity.Name,
                    ActionType = Types.ActionType.SAVE
                };
                context.ExtPartMappingToolStagingActivities.Add(logSave);
                context.SaveChanges();
                #endregion

                response = new Models.Response.Response()
                {
                    Success            = true,
                    JSON_RESPONSE_DATA = JsonConvert.SerializeObject(extPartEntry)// JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings)
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }


            //return JsonConvert.SerializeObject(commissionDataResponseObject, Formatting.None, settings); //Returns students list as JSON
        }
示例#7
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            var context             = new Magnaflow_WebEntities();
            var instantiateLogEntry = true;
            int?stagingActivityId   = null;

            Models.Response.Response response = null;
            List <ExtPartMappingToolUploadStaging> uploadStagingList = new List <ExtPartMappingToolUploadStaging>();

            try
            {
                using (var package = new ExcelPackage(file.InputStream))
                {
                    // get the first worksheet in the workbook
                    ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
                    for (int row = 1; worksheet.Cells[row, 1].Value != null; row++)
                    {
                        var oldPartId = worksheet.Cells[row, 1].Value;
                        var newPartId = worksheet.Cells[row, 2].Value;
                        #region log begin upload
                        if (instantiateLogEntry)
                        {
                            var logBeginUpload = new ExtPartMappingToolStagingActivity()
                            {
                                Time       = DateTime.UtcNow,
                                UserId     = User.Identity.Name,
                                ActionType = Types.ActionType.BEGIN_UPLOAD
                            };

                            context.ExtPartMappingToolStagingActivities.Add(logBeginUpload);
                            context.SaveChanges();
                            stagingActivityId   = logBeginUpload.StagingActivityId;
                            instantiateLogEntry = false;
                        }
                        #endregion

                        /* add to upload staging */
                        uploadStagingList.Add(new ExtPartMappingToolUploadStaging()
                        {
                            StagingActiviyId = (int)stagingActivityId,
                            OldPartId        = oldPartId.ToString(),
                            NewPartId        = newPartId.ToString()
                        });
                    }
                    context.ExtPartMappingToolUploadStagings.AddRange(uploadStagingList);

                    /*foreach(var record in uploadStagingList)
                     * {
                     *  context.ExtPartMappingToolUploadStagings.Add(record);
                     * }*/

                    context.SaveChanges();
                } // the using

                response = new Models.Response.Response()
                {
                    Success            = true,
                    JSON_RESPONSE_DATA = JsonConvert.SerializeObject(uploadStagingList)
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                response = new Models.Response.Response()
                {
                    Success            = false,
                    JSON_RESPONSE_DATA = JsonConvert.SerializeObject("Internal_Error")
                };
                return(this.Json(response, JsonRequestBehavior.AllowGet));
            }
        }