Пример #1
0
        public async Task <ActionResult> PredajOglas(Zgrade_OglasnaPloca oglasObj)
        {
            try
            {
                var identity = (ClaimsIdentity)User.Identity;
                var userGuid = identity.GetUserId();
                var user     = await _db.KompanijeUseri.FirstOrDefaultAsync(p => p.UserGuid == userGuid);

                var stanar = await _db.Zgrade_Stanari.FirstOrDefaultAsync(p => p.Id == user.Stanarid);

                var zgrada = await _db.Zgrade.FirstOrDefaultAsync(p => p.Id == stanar.ZgradaId);

                if (oglasObj.Id == 0)
                {
                    oglasObj.UserId   = user.Id;
                    oglasObj.Datum    = DateTime.Now;
                    oglasObj.ZgradaId = zgrada.Id;
                    _db.Zgrade_OglasnaPloca.Add(oglasObj);
                }
                else
                {
                    _db.Zgrade_OglasnaPloca.Attach(oglasObj);
                    _db.Entry(oglasObj).State = EntityState.Modified;
                }

                await _db.SaveChangesAsync();

                return(Json(new { success = true, msg = "" }));
            }
            catch (Exception ex) { return(Json(new { success = false, msg = ex.Message })); }
        }
Пример #2
0
        public async Task <IHttpActionResult> oglasnaEditOrCreate(Zgrade_OglasnaPloca oglas)
        {
            try
            {
                var identity  = (ClaimsIdentity)User.Identity;
                var companyId = Convert.ToInt32(identity.FindFirstValue("Cid"));
                var userGuid  = identity.GetUserId();
                var user      = await _db.KompanijeUseri.FirstOrDefaultAsync(p => p.UserGuid == userGuid);

                oglas.UserId = user.Id;

                if (oglas.Id == 0)
                {
                    _db.Zgrade_OglasnaPloca.Add(oglas);
                }
                else
                {
                    _db.Zgrade_OglasnaPloca.Attach(oglas);
                    _db.Entry(oglas).State = EntityState.Modified;
                }
                await _db.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex) { return(InternalServerError()); }
        }