Beispiel #1
0
        public async Task <bool> AddMotocycle(MotocycleAnnounceModel announce)
        {
            try
            {
                MotocycleBodyType bodyType = await _dbContext.MotocycleBodyTypes.FindAsync(announce.MotocycleBodyTypeId);

                MotocycleMake make = await _dbContext.MotocycleMakes.FindAsync(announce.MotocycleMakeId);

                DateTime addedDate = DateTime.Now;

                Motocycle unicodeAnnounce = await _dbContext.Motocycles.FindAsync(_dbContext.Motocycles.Max(c => c.Id));

                string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString();

                Motocycle motocycle = new Motocycle(bodyType, make, announce.MotocycleYear)
                {
                    AnnounceAddedDate   = addedDate,
                    AnnounceTypeId      = announce.AnnounceTypeId,
                    Price               = announce.Price,
                    CityId              = announce.CityId,
                    Description         = announce.Description,
                    PersonTypeId        = announce.PersonTypeId,
                    Email               = announce.Email,
                    PhoneNumber         = announce.PhoneNumber,
                    Condition           = announce.MotocycleCondition,
                    MotocycleBodyTypeId = announce.MotocycleBodyTypeId,
                    MotocycleKilometer  = announce.MotocycleKilometer,
                    MotocycleModel      = announce.MotocycleModel,
                    AnnounceUniqueCode  = unicode,
                    MotocycleMotor      = announce.MotocycleMotor,
                };
                await _dbContext.Motocycles.AddAsync(motocycle);

                //car files upload start
                AddDataPhoto(announce.Paths, motocycle.Id, "lib/images/transport/motocycle", FindTable.Motocycle);


                //car files upload end
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return(true);
        }
        public async Task <IActionResult> AddMotocycleBodyType(string name)
        {
            if (!String.IsNullOrEmpty(name))
            {
                try
                {
                    var motocycleBody = new MotocycleBodyType
                    {
                        Name = name,
                    };

                    await _dbContext.MotocycleBodyTypes.AddAsync(motocycleBody);

                    await _dbContext.SaveChangesAsync();

                    return(Json(motocycleBody));
                }
                catch (Exception)
                {
                    return(Json("fail"));
                }
            }
            return(Json("fail"));
        }