Exemplo n.º 1
0
        public async Task <IActionResult> Save([FromBody] LeaveType leaveType)
        {
            int result = 0;

            try
            {
                leaveType.ID = Guid.NewGuid();
                context.Add(leaveType);
                result = await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }
            return(Ok(result));
        }
        public async Task <IActionResult> Save([FromBody] EmployeeInsurance employeeInsurance)
        {
            int result = 0;

            try
            {
                employeeInsurance.EmployeeInsuranceId = Guid.NewGuid();
                context.Add(employeeInsurance);
                result = await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }
            return(Ok(result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Access,Accommodates,Bathrooms,BedTypeId,Bedrooms,CancellationPolicyId,CleaningFee,Description,ExtraPeople,GuestsIncluded,HostId,HouseRules,Interaction,IsBusinessTravelReady,Latitude,ListingUrl,Longitude,MaximumNights,MinimumNights,MonthlyPrice,Name,NeighborhoodId,NeighborhoodOverview,Notes,PictureUrl,Price,PropertyTypeId,RequireGuestPhoneVerification,RequireGuestProfilePicture,ReviewScoresAccuracy,ReviewScoresCheckin,ReviewScoresCleanliness,ReviewScoresCommunication,ReviewScoresLocation,ReviewScoresRating,ReviewScoresValue,RoomTypeId,SecurityDeposit,Space,SquareFeet,Summary,Transit,WeeklyPrice")] Listing listing)
        {
            if (ModelState.IsValid)
            {
                _context.Add(listing);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BedTypeId"]            = new SelectList(_context.BedTypes, "Id", "Name", listing.BedTypeId);
            ViewData["CancellationPolicyId"] = new SelectList(_context.CancellationPolicies, "Id", "Name", listing.CancellationPolicyId);
            ViewData["HostId"]         = new SelectList(_context.Hosts, "Id", "PictureUrl", listing.HostId);
            ViewData["NeighborhoodId"] = new SelectList(_context.Neighborhoods, "Id", "Name", listing.NeighborhoodId);
            ViewData["PropertyTypeId"] = new SelectList(_context.PropertyTypes, "Id", "Name", listing.PropertyTypeId);
            ViewData["RoomTypeId"]     = new SelectList(_context.RoomTypes, "Id", "Name", listing.RoomTypeId);
            return(View(listing));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Save([FromBody] ClaimRequest claimRequest)
        {
            int result = 0;

            try
            {
                claimRequest.ID = Guid.NewGuid();
                context.Add(claimRequest);
                result = await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }

            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Brandid,Modelid,Colorid,Status,Plate,Dailyprice")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["BrandName"] = new SelectList(_context.Brands, "Brandname", "Brandname");

            ViewData["Brandid"] = new SelectList(_context.Brands, "Id", "Id", car.Brandid);
            ViewData["Colorid"] = new SelectList(_context.Colors, "Id", "Id", car.Colorid);
            ViewData["Modelid"] = new SelectList(_context.Models, "Id", "Id", car.Modelid);

            return(View(car));
        }
Exemplo n.º 6
0
        public bool InsertFinaTable()
        {
            var finaList = new List <FinaDifficultyModel>();

            using (StreamReader r = new StreamReader(@"C:\Users\pontu\Desktop\SoP\DiveComp\DiveComp.Data\Helpers\FinaTable.json"))
            {
                string json = r.ReadToEnd();
                finaList = JsonConvert.DeserializeObject <List <FinaDifficultyModel> >(json);
            }

            foreach (var diveobject in finaList)
            {
                db.Add(diveobject);
            }

            db.SaveChanges();
            return(true);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("ID,InstitutionID,Name")] School school)
        {
            if (User.FindFirst("Role").Value == "Admin")
            {
                if (ModelState.IsValid)
                {
                    _context.Add(school);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(school));
            }
            else
            {
                return(NotFound("Access Dinied"));
            }
        }
        public IActionResult Register(AuthViewModel Auth)
        {
            System.Console.WriteLine(Auth.RegForm);
            UserModel submission = new UserModel()
            {
                FirstName       = Auth.RegForm.FirstName,
                LastName        = Auth.RegForm.LastName,
                Email           = Auth.RegForm.Email,
                Password        = Auth.RegForm.Password,
                ConfirmPassword = Auth.RegForm.ConfirmPassword
            };
            string    check = submission.Email == null ? null : submission.Email.ToLower();
            UserModel Query = _context.Users.Where(user => user.Email.ToLower() == check).FirstOrDefault();

            if (ModelState.IsValid && Query == null)
            {
                PasswordHasher <UserModel> Hasher = new PasswordHasher <UserModel> ();
                submission.Password = Hasher.HashPassword(submission, submission.Password);
                _context.Add(submission);
                _context.SaveChanges();
                HttpContext.Session.SetInt32("UserId", submission.UserId);
                return(RedirectToAction("Result"));
            }
            else
            {
                TempData["fname"]        = submission.FirstName;
                TempData["lname"]        = submission.LastName;
                TempData["emailAddress"] = submission.Email;
                foreach (string key in ModelState.Keys)
                {
                    string field = key.Substring(8);
                    System.Console.WriteLine(field);
                    ModelStateEntry entry = ModelState[key];
                    string          error = entry.Errors.Select(e => e.ErrorMessage).FirstOrDefault();
                    System.Console.WriteLine(error);
                    TempData[field] = error;
                }
                if (Query != null && TempData["Email"] == null)
                {
                    TempData["Email"] = "Email is not unique.";
                }
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Transfuzjaid,Pielegniarkaid,Badaniaid,Pacjentid,PotrzebnaIlosc,DataTransfuzji")] Transfuzja transfuzja)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transfuzja);
                await _context.SaveChangesAsync();

                _context.Attach(transfuzja).State = EntityState.Detached;
                return(RedirectToAction(nameof(Index)));
            }

            var pacjent      = _context.Pacjent.Include(x => x.Osoba);
            var pielegniarka = _context.Pielegniarka.Include(x => x.Osoba);

            ViewData["Badaniaid"]      = new SelectList(_context.Badania, "Badaniaid", "Badaniaid", transfuzja.Badaniaid);
            ViewData["Pacjentid"]      = new SelectList(pacjent, "Pacjentid", "Info", transfuzja.Pacjentid);
            ViewData["Pielegniarkaid"] = new SelectList(pielegniarka, "Pielegniarkaid", "Info", transfuzja.Pielegniarkaid);
            return(View(transfuzja));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Save([FromBody] Employee employee)
        {
            int result = 0;

            try
            {
                employee.ID             = Guid.NewGuid();
                employee.ApprovalLineId = Guid.Empty;
                employee.CreatedDate    = DateTime.Now;
                employee.ModifiedDate   = DateTime.Now;
                context.Add(employee);
                result = await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }
            return(Ok(result));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Donacjaid,Donatorid,Badaniaid,Pielegniarkaid,Typid,IloscDonacji,Datadonacji")] Donacja donacja)
        {
            if (ModelState.IsValid)
            {
                _context.Add(donacja);
                await _context.SaveChangesAsync();

                _context.Attach(donacja).State = EntityState.Detached;
                return(RedirectToAction(nameof(Index)));
            }

            var donator      = _context.Donator.Include(x => x.Osoba).Where(x => x.Osobaid != null);
            var pielegniarki = _context.Pielegniarka.Include(x => x.Osoba).Where(x => x.Osobaid != null);

            ViewData["Badaniaid"]      = new SelectList(_context.Badania, "Badaniaid", "Badaniaid", donacja.Badaniaid);
            ViewData["Donatorid"]      = new SelectList(donator, "Donatorid", "Info", donacja.Donatorid);
            ViewData["Pielegniarkaid"] = new SelectList(pielegniarki, "Pielegniarkaid", "Info", donacja.Pielegniarkaid);
            ViewData["Typid"]          = new SelectList(_context.TypDonacji, "Typid", "Typ", donacja.Typid);
            return(View(donacja));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Save([FromBody] Leave leave)
        {
            int result = 0;

            try
            {
                leave.ID           = Guid.NewGuid();
                leave.CreatedDate  = DateTime.Now;
                leave.ModifiedDate = DateTime.Now;
                leave.Status       = "Submitted";
                leave.IsTaken      = false;

                context.Add(leave);
                result = await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }
            return(Ok(result));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Adds an employee to the databse.
        /// </summary>
        /// <param name="salary"></param>
        /// <param name="properties"></param>
        /// <returns>returns the number of rows affected </returns>
        public int AddEmployee(double salary, params string[] properties)
        {
            string DeptID = FetchDepartmentId(properties[5]);

            CheckForDuplicateEmail(properties[2]);
            using var context = new ModelContext();
            var newEmployee = new Employee
            {
                EmployeeId   = Guid.NewGuid().ToString(),
                FirstName    = properties[0],
                LastName     = properties[1],
                Email        = properties[2],
                PhoneNumber  = properties[3],
                State        = properties[4],
                Salary       = salary,
                DepartmentId = DeptID
            };

            context.Add <Employee>(newEmployee);
            return(context.SaveChanges());
        }
Exemplo n.º 14
0
 protected override void AddItem(EduLevelInfo item)
 {
     ModelContext.Add(item);
     ModelContext.SaveChanges();
 }
Exemplo n.º 15
0
        public void Run()
        {
            UiHelpers.InitConsole();

            // drop database file for testing purpose
            //File.Delete(ModelContext.DataBaseFile);

            using (var db = new ModelContext()) {
                // create DB if not exists
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                GsoLogger.LoggingEnabled = false;

                // populate DB
                if (db.Persons.OfType <Admin>().Count() == 0)
                {
                    db.Add(new Admin()
                    {
                        FirstName = "Adalbert", LastName = "Acker", Department = "Service"
                    });
                    db.Add(new Admin()
                    {
                        FirstName = "Agate", LastName = "Ahrweiler", Department = "Service"
                    });
                    db.SaveChanges();
                }
                if (db.Persons.OfType <Employee>().Where(p => !(p is Admin)).Count() == 0)
                {
                    var boss = new Employee()
                    {
                        FirstName = "Egon", LastName = "Boss", Department = "Customer"
                    };
                    db.Add(boss);
                    db.Add(new Employee()
                    {
                        FirstName = "Ernst", LastName = "Ecker", LineManager = boss, Department = "Customer"
                    });
                    db.Add(new Employee()
                    {
                        FirstName = "Emilia", LastName = "Eichberg", LineManager = boss, Department = "Customer"
                    });
                    db.SaveChanges();
                }
                if (db.Persons.OfType <Member>().Count() == 0)
                {
                    db.AddRange(SvcImport.ImportMembers3(@"../../../Data/fake-persons.txt"));
                    db.SaveChanges();
                }
                if (db.Mediums.Count() == 0)
                {
                    var mediums = SvcImport.ImportMediums3(@"../../../Data/spiegel-bestseller.txt");
                    db.AddRange(mediums);
                    db.SaveChanges();
                }
                if (db.Items.Count() == 0)
                {
                    db.Add(new Item()); // { Id = 1000 });
                    db.Add(new Item());
                    db.Add(new Item());
                    db.SaveChanges();
                }

                GsoLogger.LoggingEnabled = true;

                //ShowStuff();

                var svc  = new SvcCityLibrary(db);
                var menu = new UiMenu(svc);
                while (true)
                {
                    menu.ShowMainMenu();
                    Console.ReadLine();
                }

                Console.WriteLine("\nDone.");
                Console.ReadLine();
            }
        }
Exemplo n.º 16
0
 protected override void AddItem(PositionInfo item)
 {
     ModelContext.Add(item);
     ModelContext.SaveChanges();
 }
Exemplo n.º 17
0
        public IActionResult AddCodes([Bind("CountryId,NetworkId,R,Values")] Codes codes)
        {
            if (ModelState.IsValid)
            {
                bool _isNewCodeAdded = false;

                foreach (var code in codes.Values)
                {
                    var codeInDb = _context.Codes.Where(c => c.R == codes.R && c.Value == code).FirstOrDefault();
                    if (codeInDb == null)
                    {
                        #region Reduce codes
                        if (codes.R.Length == 1)
                        {
                            var _Rcodes = _context.Codes.Where(c => c.R == codes.R);
                            // R = root, nothing to add
                            if (_Rcodes.Count() != 0 && _Rcodes.FirstOrDefault().Value == null)
                            {
                                break;
                            }

                            // all codes of specific R and network
                            var _codesByNetworkAndR = _Rcodes.Where(c => c.NetworkId == codes.NetworkId);

                            if (_codesByNetworkAndR != null)
                            {
                                // all entries d** and dd*
                                var _entriesCodes = _codesByNetworkAndR.Where(c => c.Value.StartsWith(code.Remove(code.Length - 2)));
                                if (codes.Values.Count() == 1)
                                {
                                    if (_entriesCodes != null)
                                    {
                                        // filter codes to find AB codes of one network // 3 -> 2
                                        List <Code> _threeDigitsCodes = new List <Code>();
                                        foreach (var c in _entriesCodes)
                                        {
                                            if (c.Value.Length == 3 && c.Value.StartsWith(code.Remove(code.Length - 1)))
                                            {
                                                _threeDigitsCodes.Add(c);
                                            }
                                        }

                                        if (_threeDigitsCodes.Count > 0)
                                        {
                                            if (_threeDigitsCodes.Count == 9)
                                            {
                                                // check if DB contains collapsed codes of specific network. Ex.: [country][R][00*]
                                                // 2 -> 1
                                                List <Code> _twoDigitsCodes = new List <Code>();
                                                foreach (var _code in _entriesCodes)
                                                {
                                                    if (_code.Value.Length == 2 && _code.Value.StartsWith(code.Remove(code.Length - 2)))
                                                    {
                                                        _twoDigitsCodes.Add(_code);
                                                    }
                                                }

                                                if (_twoDigitsCodes.Count() == 9)
                                                {
                                                    // check if DB contains collapsed codes by R. Ex.: [country][R]

                                                    // 1 -> R
                                                    List <Code> _oneDigitCodes = new List <Code>();
                                                    foreach (var _code in _entriesCodes)
                                                    {
                                                        if (_code.Value.Length == 1)
                                                        {
                                                            _oneDigitCodes.Add(_code);
                                                        }
                                                    }

                                                    if (_oneDigitCodes.Count == 99)
                                                    {
                                                        _context.Codes.RemoveRange(_oneDigitCodes);
                                                        _context.Codes.Add(new Code()
                                                        {
                                                            CountryId = codes.CountryId,
                                                            NetworkId = codes.NetworkId,
                                                            R         = codes.R,
                                                            Value     = null
                                                        });
                                                        _isNewCodeAdded = true;
                                                    }
                                                    else
                                                    {
                                                        _context.Codes.RemoveRange(_twoDigitsCodes);
                                                        _context.Codes.RemoveRange(_threeDigitsCodes);
                                                        // collapse codes to one digit code (value)
                                                        _context.Codes.Add(new Code()
                                                        {
                                                            CountryId = codes.CountryId,
                                                            NetworkId = codes.NetworkId,
                                                            R         = codes.R,
                                                            Value     = code.Remove(code.Length - 2)
                                                        });
                                                        _isNewCodeAdded = true;
                                                    }
                                                }
                                                else
                                                {
                                                    _context.Codes.RemoveRange(_threeDigitsCodes);
                                                    _context.Codes.Add(new Code()
                                                    {
                                                        CountryId = codes.CountryId,
                                                        NetworkId = codes.NetworkId,
                                                        R         = codes.R,
                                                        Value     = code.Remove(code.Length - 1)
                                                    });
                                                    _isNewCodeAdded = true;
                                                }
                                            }
                                            else
                                            {
                                                _context.Codes.Add(new Code()
                                                {
                                                    CountryId = codes.CountryId, NetworkId = codes.NetworkId, R = codes.R, Value = code
                                                });
                                                _isNewCodeAdded = true;
                                            }
                                        }
                                        else
                                        {
                                            _context.Codes.Add(new Code()
                                            {
                                                CountryId = codes.CountryId, NetworkId = codes.NetworkId, R = codes.R, Value = code
                                            });
                                            _isNewCodeAdded = true;
                                        }
                                    }
                                }
                                else if (codes.Values.Count() == 10)
                                {
                                    // 2 -> 1
                                    List <Code> _twoDigitsCodes   = new List <Code>();
                                    List <Code> _threeDigitsCodes = new List <Code>();
                                    foreach (var _code in _entriesCodes)
                                    {
                                        if (_code.Value.Length == 2 && _code.Value.StartsWith(code.Remove(code.Length - 2)))
                                        {
                                            _twoDigitsCodes.Add(_code);
                                        }
                                        else if (_code.Value.Length == 3 && _code.Value.StartsWith(code.Remove(code.Length - 2)))
                                        {
                                            _threeDigitsCodes.Add(_code);
                                        }
                                    }

                                    if (_twoDigitsCodes.Count == 9)
                                    {
                                        // 1 -> R
                                        List <Code> _oneDigitCodes = new List <Code>();
                                        foreach (var _code in _entriesCodes)
                                        {
                                            if (_code.Value.Length == 1)
                                            {
                                                _oneDigitCodes.Add(_code);
                                            }
                                        }

                                        if (_oneDigitCodes.Count == 9)
                                        {
                                            _context.Codes.RemoveRange(_oneDigitCodes);
                                            if (_threeDigitsCodes.Count > 0)
                                            {
                                                _context.Codes.RemoveRange(_threeDigitsCodes);
                                            }
                                            _context.Codes.Add(new Code()
                                            {
                                                CountryId = codes.CountryId,
                                                NetworkId = codes.NetworkId,
                                                R         = codes.R,
                                                Value     = null
                                            });
                                            _isNewCodeAdded = true;
                                        }
                                        else
                                        {
                                            _context.Codes.RemoveRange(_twoDigitsCodes);
                                            if (_threeDigitsCodes.Count > 0)
                                            {
                                                _context.Codes.RemoveRange(_threeDigitsCodes);
                                            }
                                            _context.Codes.Add(new Code()
                                            {
                                                CountryId = codes.CountryId,
                                                NetworkId = codes.NetworkId,
                                                R         = codes.R,
                                                Value     = code.Remove(code.Length - 2)
                                            });
                                            _isNewCodeAdded = true;
                                        }
                                    }
                                    else
                                    {
                                        _context.Codes.Add(new Code()
                                        {
                                            CountryId = codes.CountryId,
                                            NetworkId = codes.NetworkId,
                                            R         = codes.R,
                                            Value     = code.Remove(code.Length - 1)
                                        });
                                        _isNewCodeAdded = true;
                                    }
                                    break;
                                }
                                else if (codes.Values.Count() == 500)
                                {
                                    // 1 -> R
                                    List <Code> _oneDigitCodes = new List <Code>();
                                    byte        _count         = 0;
                                    foreach (var _code in _codesByNetworkAndR)
                                    {
                                        if (_code.Value?.Length == 1)
                                        {
                                            _oneDigitCodes.Add(_code);
                                        }
                                    }
                                    for (int i = 0; i < 5; i++)
                                    {
                                        if (_oneDigitCodes.Find(c => c.Value == i.ToString()) != null)
                                        {
                                            ++_count;
                                        }
                                    }

                                    // check if from one table
                                    if (_oneDigitCodes.Count == 5 && _count == 5)
                                    {
                                        _context.RemoveRange(_Rcodes);
                                        _context.Add(new Code()
                                        {
                                            CountryId = codes.CountryId,
                                            NetworkId = codes.NetworkId,
                                            R         = codes.R,
                                            Value     = null
                                        });
                                        _isNewCodeAdded = true;
                                    }
                                    else
                                    {
                                        // 3 -> 1
                                        _context.RemoveRange(_oneDigitCodes);
                                        for (int i = 0; i < codes.Values.Count(); i += 100)
                                        {
                                            _context.Codes.Add(new Code()
                                            {
                                                CountryId = codes.CountryId,
                                                NetworkId = codes.NetworkId,
                                                R         = codes.R,
                                                Value     = codes.Values[i].Remove(codes.Values[i].Length - 2)
                                            });
                                        }

                                        _isNewCodeAdded = true;
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                _context.Codes.Add(new Code()
                                {
                                    CountryId = codes.CountryId, NetworkId = codes.NetworkId, R = codes.R, Value = code
                                });
                                _isNewCodeAdded = true;
                            }
                        }
                        else
                        {
                            if (codes.Values.Count() == 1)
                            {
                                if (codes.R.Remove(codes.R.Length - 1).Length > 0)
                                {
                                    string _zone = codes.R;
                                    string _code = code;
                                    Dictionary <string, string> _keyValuePairs = new Dictionary <string, string>();
                                    while (_zone.Remove(_zone.Length - 1).Length > 0)
                                    {
                                        _code = $"{_zone[_zone.Length - 1]}{_code.Remove(_code.Length - 1)}";
                                        _keyValuePairs.Add(_zone.Remove(_zone.Length - 1), _code);
                                        _zone = _zone.Remove(_zone.Length - 1);
                                    }
                                    // retreive root code
                                    Code _rootCode = null;
                                    foreach (var item in _keyValuePairs)
                                    {
                                        _rootCode = _context.Codes.Where(c => c.R == item.Key && c.Value == item.Value).FirstOrDefault();
                                    }

                                    if (_rootCode != null)
                                    {
                                        int _networkId = 0;
                                        // expand _rootCode
                                        string t = $"{codes.R}{code}".Remove(0, $"{_rootCode.R}{_rootCode.Value}".Length);
                                        for (int i = 0; i <= 9; i++)
                                        {
                                            // codes painting
                                            if (i.ToString()[0] != t[0])
                                            {
                                                _networkId = _rootCode.NetworkId;
                                            }
                                            else
                                            {
                                                _networkId = codes.NetworkId;
                                            }

                                            _context.Codes.Add(new Code()
                                            {
                                                CountryId = codes.CountryId,
                                                NetworkId = _networkId,
                                                R         = $"{_rootCode.R}{_rootCode.Value[0]}",
                                                Value     = $"{_rootCode.Value[1]}{_rootCode.Value[2]}{i}"
                                            });
                                        }
                                        // add new code
                                        _context.Codes.Add(new Code()
                                        {
                                            CountryId = codes.CountryId,
                                            NetworkId = codes.NetworkId,
                                            R         = codes.R,
                                            Value     = code
                                        });

                                        // delete _rootCode
                                        if (_context.Codes.Remove(_rootCode) != null)
                                        {
                                            _isNewCodeAdded = true;
                                            break;
                                        }
                                    }
                                }

                                var _inLineDBCodes = _context.Codes.Where(c =>
                                                                          c.NetworkId == codes.NetworkId &&
                                                                          c.R == codes.R &&
                                                                          c.Value.StartsWith(code.Remove(code.Length - 1)));
                                if (_inLineDBCodes.Count() == 9)
                                {
                                    string _parentCode = codes.R[codes.R.Length - 1] + code.Remove(code.Length - 1);
                                    _context.Codes.Add(new Code()
                                    {
                                        CountryId = codes.CountryId,
                                        NetworkId = codes.NetworkId,
                                        R         = codes.R.Remove(codes.R.Length - 1),
                                        Value     = _parentCode
                                    });
                                    _isNewCodeAdded = true;
                                    _context.Codes.RemoveRange(_inLineDBCodes);
                                    break;
                                }
                            }
                            else if (codes.Values.Count() == 10)
                            {
                                string _parentCode = codes.R[codes.R.Length - 1] + code.Remove(code.Length - 1);
                                _context.Codes.Add(new Code()
                                {
                                    CountryId = codes.CountryId,
                                    NetworkId = codes.NetworkId,
                                    R         = codes.R.Remove(codes.R.Length - 1),
                                    Value     = _parentCode
                                });
                                _isNewCodeAdded = true;
                                break;
                            }

                            _context.Codes.Add(new Code()
                            {
                                CountryId = codes.CountryId, NetworkId = codes.NetworkId, R = codes.R, Value = code
                            });
                            _isNewCodeAdded = true;
                        }
                        #endregion
                    }
                    else
                    {//reassign code
                        if (codeInDb.NetworkId == codes.NetworkId)
                        {
                            continue;
                        }
                        codeInDb.NetworkId             = codes.NetworkId;
                        _context.Entry(codeInDb).State = EntityState.Modified;
                        _isNewCodeAdded = true;
                    }
                }
                if (_isNewCodeAdded == false)
                {
                    return(new StatusCodeResult(StatusCodes.Status400BadRequest));
                }

                _context.SaveChanges();
                return(new StatusCodeResult(StatusCodes.Status200OK));
            }
            return(new StatusCodeResult(StatusCodes.Status400BadRequest));
        }
Exemplo n.º 18
0
 protected override void AddItem(DocumentTypeInfo item)
 {
     ModelContext.Add <DocumentTypeInfo> (item);
     ModelContext.SaveChanges();
 }
Exemplo n.º 19
0
 protected override void AddItem(ScienceRecordTypeInfo item)
 {
     ModelContext.Add(item);
     ModelContext.SaveChanges();
 }
Exemplo n.º 20
0
 protected override void AddItem(AchievementTypeInfo item)
 {
     ModelContext.Add(item);
     ModelContext.SaveChanges();
 }
Exemplo n.º 21
0
 protected override void AddItem(EduFormInfo item)
 {
     ModelContext.Add <EduFormInfo> (item);
     ModelContext.SaveChanges();
 }