Beispiel #1
0
        public ActionResult Delete(ExtPartMapping entry)
        {
            var context  = new Magnaflow_WebEntitiesProd();
            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
        }
Beispiel #2
0
        public ActionResult Commit(List <ExtPartMappingToolUploadStaging> stagingList)
        {
            var context = new Magnaflow_WebEntitiesProd();

            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));
            }
        }
Beispiel #3
0
        public ActionResult Save(Models.Request.NestedViews.Save saveModel)
        {
            var context  = new Magnaflow_WebEntitiesProd();
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            Models.Response.Response response     = null;
            ExtPartMapping           extPartEntry = null; //To do: need to change this with 'Mine' once we decide it's ok to change databases

            //Models.CommissionData commissionDataResponseObject = null;

            /*
             * Do checks here making sure input is as expectied
             */
            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
        }
Beispiel #4
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            var context             = new Magnaflow_WebEntitiesProd();
            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));
            }
        }