예제 #1
0
        //Full Data Mapping
        public PrimarySourceDataModel MappingToPrimarySourceDataModelFullData(PrimarySource obj)
        {
            PrimarySourceDataModel ReturnObj = new PrimarySourceDataModel()
            {
                Id          = obj.Id,
                Code        = obj.Code,
                Name        = obj.Name,
                FacId       = obj.FactoryId,
                FacName     = GetFactoryName(obj.FactoryId),
                DesignValue = obj.DesignValue,
                MaxCurrent  = obj.MaxCurrent,
                Topology    = obj.Topology,
                Type        = obj.Type
            };

            foreach (var item in obj.secondarySources)
            {
                ReturnObj.secondarySources.Add(new SecoundrySouresDataModelSim()
                {
                    Id                = item.Id,
                    Code              = item.Code,
                    Name              = item.Name,
                    PS_Id             = obj.Id,
                    PirmarySourceName = obj.Name
                });
            }
            return(ReturnObj);
        }
예제 #2
0
        //================================================================
        //Setters
        //Create PrimarySource
        public async Task <bool> CreatePrimarySourceAsync(PrimarySourceDataModel obj)
        {
            //mapping
            var PriamrySource = MappingToPrimarySource(obj);

            //Adding To Db
            _Context.PrimarySource.Add(PriamrySource);
            await _Context.SaveChangesAsync();

            var value = _Context.PrimarySource.Last();

            //value.Code = "" + value.Id;
            _Context.SaveChanges();



            // PEAK POWER TABLE
            powerPeak peak = new powerPeak()
            {
                primarySourceId = Convert.ToInt16(value.Code),
                peakP1          = 0,
                peakP2          = 0,
                peakP3          = 0,
            };

            _Context.powerPeak.Add(peak);
            _Context.SaveChanges();
            return(true);
        }
        public async Task <IActionResult> Edit(PrimarySourceDataModel obj)
        {
            PrimarySourceSerivce ps = new PrimarySourceSerivce(_Context);

            bool tr = await ps.EditPrimarySource(obj);

            return(RedirectToAction(nameof(Index)));
        }
예제 #4
0
        public PrimarySource MappingToPrimarySourceWithId(PrimarySourceDataModel obj)
        {
            PrimarySource result = new PrimarySource()
            {
                Id          = obj.Id,
                Name        = obj.Name,
                Code        = obj.Code,
                FactoryId   = obj.FacId,
                DesignValue = obj.DesignValue,
                MaxCurrent  = obj.MaxCurrent,
                Topology    = obj.Topology,
                Type        = obj.Type
            };

            return(result);
        }
예제 #5
0
        //Mapping Single object To PSDM
        public PrimarySourceDataModel MappingToPrimarySourceDataModel(PrimarySource obj)
        {
            PrimarySourceDataModel ReturnObj = new PrimarySourceDataModel()
            {
                Id          = obj.Id,
                Code        = obj.Code,
                Name        = obj.Name,
                FacId       = obj.FactoryId,
                FacName     = GetFactoryName(obj.FactoryId),
                DesignValue = obj.DesignValue,
                MaxCurrent  = obj.MaxCurrent,
                Topology    = obj.Topology,
                Type        = obj.Type
            };

            return(ReturnObj);
        }
        public async Task <IActionResult> Create(PrimarySourceDataModel obj)
        {
            PrimarySourceSerivce ps = new PrimarySourceSerivce(_Context);
            var y = ps.GetPrimaryByName(obj.Name, obj.FacId);

            if (y != null)
            {
                FactoryService fs = new FactoryService(_Context);
                ViewBag.factories = fs.GetAllFactoriesSimple();
                ModelState.AddModelError("Name", "Name is already exist");
                return(View("homeCreate", obj));
            }


            bool created = await ps.CreatePrimarySourceAsync(obj);

            return(RedirectToAction("Index", "PrimarySource"));
        }
예제 #7
0
        public async Task <bool> EditPrimarySource(PrimarySourceDataModel obj)
        {
            PrimarySource result = new PrimarySource()
            {
                Id          = obj.Id,
                Name        = obj.Name,
                DesignValue = obj.DesignValue,
                MaxCurrent  = obj.MaxCurrent,
                Topology    = obj.Topology,
                FactoryId   = obj.FacId,
                Code        = obj.Code,
                Type        = obj.Type
            };

            _Context.PrimarySource.Update(result);
            await _Context.SaveChangesAsync();

            return(true);
        }
        public IActionResult Create(int Id)
        {
            if (Id != -1)
            {
                PrimarySourceDataModel viewModel = new PrimarySourceDataModel()
                {
                    FacId = Id
                };
                return(View(viewModel));
            }
            else
            {
                FactoryService       fs = new FactoryService(_Context);
                PrimarySourceSerivce ps = new PrimarySourceSerivce(_Context);
                ViewBag.factories = fs.GetAllFactoriesSimple();
                ViewBag.primaries = ps.GetAllPrimarySources();


                return(View("homeCreate"));
            }
        }