Esempio n. 1
0
        public bool EditLoadAsyn(LoadDataModel obj)
        {
            string ldFunction;

            if (obj.Function == "-1")
            {
                ldFunction = obj.FunctionOther;

                bool checkFunc = CheckFunction(ldFunction);
                if (checkFunc == false)
                {
                    Function func = new Function()
                    {
                        FunctionName = ldFunction
                    };
                    _con.Functions.Add(func);
                    _con.SaveChanges();
                }
            }
            else
            {
                ldFunction = obj.Function;
            }



            Load ld = new Load
            {
                Connection = obj.Connection,
                PhaseType  = obj.PhaseType,
                Function   = ldFunction,
                SourceId   = obj.SourceId,
                Id         = obj.Id,
                Type       = obj.Type,
                code       = obj.code,
                name       = obj.name
            };
            Loadparameter ldpram = new Loadparameter
            {
                Id            = obj.loadpramid,
                Power         = obj.Power,
                PowerFactor   = obj.PowerFactor,
                RatingCurrent = obj.RatingCurrent,
                RatingTemp    = obj.RatingTemp,
                RatingVoltage = obj.RatingVoltage,
                Type          = obj.Type
            };

            ld.LoadInfo = ldpram;
            _con.Load.Update(ld);
            _con.Loadparameter.Update(ldpram);
            _con.SaveChanges();
            return(true);
        }
Esempio n. 2
0
        public async Task <bool> CreateLoadAsync(LoadDataModel obj)
        {
            //mapping
            var load = MappingtoLoad(obj);

            //Adding To Db
            _con.Load.Add(load);
            await _con.SaveChangesAsync();

            Loadparameter par = new Loadparameter
            {
                Power         = obj.Power,
                PowerFactor   = obj.PowerFactor,
                RatingCurrent = obj.RatingCurrent,
                RatingTemp    = obj.RatingTemp,
                RatingVoltage = obj.RatingVoltage,
                Type          = obj.Type,
            };

            _con.Loadparameter.Add(par);

            var value = _con.Load.Last();

            value.code     = value.Id;
            value.LoadInfo = par;
            _con.SaveChanges();

            // lw mtwsl b primary
            if (obj.SourceId % 2 != 0)
            {
                PhasesConnection phase = new PhasesConnection();
                phase.SourceId   = obj.SourceId;
                phase.SourceType = new PrimarySourceSerivce(_con).GetPrimarySourceFromDBByCode(obj.SourceId).Type;

                if (obj.Type == "1")
                {
                    if (obj.dN1 == 1)
                    {
                        phase.dN1 = 1;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN1 == 2)
                    {
                        phase.dN2 = 1;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN3 = 1;
                        phase.sN3 = "l" + value.Id;
                    }
                }
                else
                {
                    if (obj.dN1 == 1)
                    {
                        phase.dN1 = 1;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN1 == 2)
                    {
                        phase.dN2 = 1;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN3 = 1;
                        phase.sN3 = "l" + value.Id;
                    }


                    if (obj.dN2 == 1)
                    {
                        phase.dN1 = 2;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN2 == 2)
                    {
                        phase.dN2 = 2;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN2 = 2;
                        phase.sN3 = "l" + value.Id;
                    }


                    if (obj.dN3 == 1)
                    {
                        phase.dN1 = 3;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN3 == 2)
                    {
                        phase.dN2 = 3;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN3 = 3;
                        phase.sN3 = "l" + value.Id;
                    }
                }

                _con.PhasesConnection.Add(phase);
                await _con.SaveChangesAsync();
            }
            // lw mtwsl bsec
            else
            {
                //connect to secondry source phases
                PhasesConnection phase = new PhasesConnectionService(_con).getPhaseBySourceId(obj.SourceId);
                if (obj.PhaseType == "1")
                {
                    if (obj.dN1 == 1)
                    {
                        phase.dN1 = 1;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN1 == 2)
                    {
                        phase.dN2 = 1;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN3 = 1;
                        phase.sN3 = "l" + value.Id;
                    }
                }
                else
                {
                    if (obj.dN1 == 1)
                    {
                        phase.dN1 = 1;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN1 == 2)
                    {
                        phase.dN2 = 1;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN3 = 1;
                        phase.sN3 = "l" + value.Id;
                    }


                    if (obj.dN2 == 1)
                    {
                        phase.dN1 = 2;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN2 == 2)
                    {
                        phase.dN2 = 2;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN2 = 2;
                        phase.sN3 = "l" + value.Id;
                    }


                    if (obj.dN3 == 1)
                    {
                        phase.dN1 = 3;
                        phase.sN1 = "l" + value.Id;
                    }
                    else if (obj.dN3 == 2)
                    {
                        phase.dN2 = 3;
                        phase.sN2 = "l" + value.Id;
                    }
                    else
                    {
                        phase.dN3 = 3;
                        phase.sN3 = "l" + value.Id;
                    }
                }
                _con.PhasesConnection.Update(phase);
            }



            await _con.SaveChangesAsync();

            return(true);
        }