Пример #1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            LocationAbbreviation locationAbbreviation = await db.LocationAbbreviations.FindAsync(id);

            db.LocationAbbreviations.Remove(locationAbbreviation);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LocationAbbreviation locationAbbreviation = await db.LocationAbbreviations.FindAsync(id);

            if (locationAbbreviation == null)
            {
                return(HttpNotFound());
            }
            return(View(locationAbbreviation));
        }
Пример #3
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Position,Abbreviation,CreatedOn,CreatedBy")] LocationAbbreviation locationAbbreviation)
        {
            if (ModelState.IsValid)
            {
                locationAbbreviation.ModifiedBy = HttpContext.User.Identity.Name;
                locationAbbreviation.ModifiedOn = DateTime.Now;

                db.Entry(locationAbbreviation).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(locationAbbreviation));
        }
        /// <summary>
        /// Get the abbreviated names for a submitted location name.
        /// </summary>
        /// <param name="name">Name of the location</param>
        /// <param name="abbreviationMapping">Object of type LocationAbbreviation</param>
        /// <returns>List of abbreviated names for the submitted location name</returns>
        ///
        private List <string> GetAbbreviatedNames(string name, LocationAbbreviation abbreviationMapping)
        {
            var indexOf       = name.ToLower().IndexOf(abbreviationMapping.Name.ToLower(), StringComparison.Ordinal);
            var truncatedName = name.Remove(indexOf, abbreviationMapping.Name.Length);
            var abbreviations = abbreviationMapping.Abbreviations.Split(',');

            var abbreviationList = new List <string>();

            foreach (var abbreviation in abbreviations)
            {
                abbreviationList.Add(truncatedName.Substring(0, indexOf) + abbreviation + truncatedName.Substring(indexOf));
            }

            return(abbreviationList);
        }